如何在 TensorFlow 的急切执行中使用 Keras.applications' ResNeXt?
How can I use the Keras.applications' ResNeXt in TensorFlow's eager execution?
我正在尝试从 TensorFlow 1.10 中的 Keras applications 获取 ResNet101 或 ResNeXt,出于某种原因它们仅在 Keras 的存储库中可用:
import tensorflow as tf
from keras import applications
tf.enable_eager_execution()
resnext = applications.resnext.ResNeXt101(include_top=False, weights='imagenet', input_shape=(SCALED_HEIGHT, SCALED_WIDTH, 3), pooling=None)
但是,这会导致:
Traceback (most recent call last):
File "myscript.py", line 519, in get_fpn
resnet = applications.resnet50.ResNet50(include_top=False, weights='imagenet', input_shape=(SCALED_HEIGHT, SCALED_WIDTH, 3), pooling=None)
File "Keras-2.2.4-py3.5.egg/keras/applications/__init__.py", line 28, in wrapper
return base_fun(*args, **kwargs)
File "Keras-2.2.4-py3.5.egg/keras/applications/resnet50.py", line 11, in ResNet50
return resnet50.ResNet50(*args, **kwargs)
File "Keras_Applications-1.0.8-py3.5.egg/keras_applications/resnet50.py", line 214, in ResNet50
img_input = layers.Input(shape=input_shape)
File "Keras-2.2.4-py3.5.egg/keras/engine/input_layer.py", line 178, in Input
input_tensor=tensor)
File "Keras-2.2.4-py3.5.egg/keras/legacy/interfaces.py", line 91, in wrapper
return func(*args, **kwargs)
File "Keras-2.2.4-py3.5.egg/keras/engine/input_layer.py", line 87, in __init__
name=self.name)
File "Keras-2.2.4-py3.5.egg/keras/backend/tensorflow_backend.py", line 529, in placeholder
x = tf.placeholder(dtype, shape=shape, name=name)
File "tensorflow/python/ops/array_ops.py", line 1732, in placeholder
raise RuntimeError("tf.placeholder() is not compatible with "
RuntimeError: tf.placeholder() is not compatible with eager execution.
我从其 GitHub master 分支安装了 Keras,因为 Keras 和 TensorFlow 的 Keras API 的 pip 安装出于某种奇怪的原因不包括 ResNet101、ResNetv2、ResNeXt 等。有人知道吗我如何在 TensorFlow 的急切执行中 运行 这样的模型(最好是 ResNeXt)?
如错误所示,tf.placeholder() 用作使用 feed_dict 将数据馈送到 tf 会话的占位符,与急切模式不兼容。
这个 link 用一个例子很好地解释了它:https://github.com/tensorflow/tensorflow/issues/18165#issuecomment-377841925
您可以使用 tf.keras.applications 中的模型来实现此目的。我试过 TF2.0 Beta 版。
import tensorflow as tf
resnext = tf.keras.applications.ResNeXt50(weights=None)
print(tf.executing_eagerly())
正确
ResNeXt 模型不可用(我必须进行一些更改,例如将 resnext.py 从 keras/applications 复制到 tensorflow/python/keras/applications 并更改为 __init__.py 等),但您可以尝试使用现有模型,如 ResNet50,如果它们有效,那么您可以尝试移植 ResNeXt。
我正在尝试从 TensorFlow 1.10 中的 Keras applications 获取 ResNet101 或 ResNeXt,出于某种原因它们仅在 Keras 的存储库中可用:
import tensorflow as tf
from keras import applications
tf.enable_eager_execution()
resnext = applications.resnext.ResNeXt101(include_top=False, weights='imagenet', input_shape=(SCALED_HEIGHT, SCALED_WIDTH, 3), pooling=None)
但是,这会导致:
Traceback (most recent call last):
File "myscript.py", line 519, in get_fpn
resnet = applications.resnet50.ResNet50(include_top=False, weights='imagenet', input_shape=(SCALED_HEIGHT, SCALED_WIDTH, 3), pooling=None)
File "Keras-2.2.4-py3.5.egg/keras/applications/__init__.py", line 28, in wrapper
return base_fun(*args, **kwargs)
File "Keras-2.2.4-py3.5.egg/keras/applications/resnet50.py", line 11, in ResNet50
return resnet50.ResNet50(*args, **kwargs)
File "Keras_Applications-1.0.8-py3.5.egg/keras_applications/resnet50.py", line 214, in ResNet50
img_input = layers.Input(shape=input_shape)
File "Keras-2.2.4-py3.5.egg/keras/engine/input_layer.py", line 178, in Input
input_tensor=tensor)
File "Keras-2.2.4-py3.5.egg/keras/legacy/interfaces.py", line 91, in wrapper
return func(*args, **kwargs)
File "Keras-2.2.4-py3.5.egg/keras/engine/input_layer.py", line 87, in __init__
name=self.name)
File "Keras-2.2.4-py3.5.egg/keras/backend/tensorflow_backend.py", line 529, in placeholder
x = tf.placeholder(dtype, shape=shape, name=name)
File "tensorflow/python/ops/array_ops.py", line 1732, in placeholder
raise RuntimeError("tf.placeholder() is not compatible with "
RuntimeError: tf.placeholder() is not compatible with eager execution.
我从其 GitHub master 分支安装了 Keras,因为 Keras 和 TensorFlow 的 Keras API 的 pip 安装出于某种奇怪的原因不包括 ResNet101、ResNetv2、ResNeXt 等。有人知道吗我如何在 TensorFlow 的急切执行中 运行 这样的模型(最好是 ResNeXt)?
如错误所示,tf.placeholder() 用作使用 feed_dict 将数据馈送到 tf 会话的占位符,与急切模式不兼容。
这个 link 用一个例子很好地解释了它:https://github.com/tensorflow/tensorflow/issues/18165#issuecomment-377841925
您可以使用 tf.keras.applications 中的模型来实现此目的。我试过 TF2.0 Beta 版。
import tensorflow as tf
resnext = tf.keras.applications.ResNeXt50(weights=None)
print(tf.executing_eagerly())
正确
ResNeXt 模型不可用(我必须进行一些更改,例如将 resnext.py 从 keras/applications 复制到 tensorflow/python/keras/applications 并更改为 __init__.py 等),但您可以尝试使用现有模型,如 ResNet50,如果它们有效,那么您可以尝试移植 ResNeXt。