[英]How to use models from keras.applications for transfer learnig?
[英]How can I use the Keras.applications' ResNeXt in TensorFlow's eager execution?
我正在嘗試從TensorFlow 1.10的Keras應用程序中獲取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會話,但與eager模式不兼容。
這個鏈接很好地解釋了一個例子: 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 /應用程序復制到tensorflow / python / keras / applications並更改為__init__.py等),但是如果存在,您可以嘗試使用ResNet50這樣的現有模型他們工作,然后您可以嘗試移植ResNeXt。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.