我访问了:https://tfhub.dev/google/imagenet/resnet_v2_50/feature_vector/5
我找到了"用法"。并复制到colab:
m = tf.keras.Sequential([
hub.KerasLayer("https://tfhub.dev/google/imagenet/resnet_v2_50/feature_vector/5",
trainable=False), # Can be True, see below.
tf.keras.layers.Dense(num_classes, activation='softmax')
])
然而,我跑了,仍然得到这个:
InvalidArgumentError Traceback (most recent call last)
<ipython-input-66-52a976264686> in <module>()
1 m = tf.keras.Sequential([
2 hub.KerasLayer("https://tfhub.dev/google/imagenet/resnet_v2_50/feature_vector/5",
----> 3 trainable=False), # Can be True, see below.
4 tf.keras.layers.Dense(num_classes, activation='softmax')
5 ])
19 frames
/usr/local/lib/python3.7/dist-packages/six.py in raise_from(value, from_value)
InvalidArgumentError: Unsuccessful TensorSliceReader constructor: Failed to get matching files on /tmp/tfhub_modules/02229962626ef521d65cf8ce349d83f59c4e3f51/variables/variables: Unimplemented: File system scheme '[local]' not implemented (file: '/tmp/tfhub_modules/02229962626ef521d65cf8ce349d83f59c4e3f51/variables/variables') [Op:Identity]
我可能做错了什么?我完全复制了它,TensorFlow也被导入为tf。非常感谢您的帮助。
可以执行如下代码
import tensorflow as tf
print(tf.__version__)
import tensorflow_hub as hub
print(hub.__version__)
num_classes = 10
m = tf.keras.Sequential([
hub.KerasLayer("https://tfhub.dev/google/imagenet/resnet_v2_50/feature_vector/5",
trainable=False), # Can be True, see below.
tf.keras.layers.Dense(num_classes, activation='softmax')
])
m.build([None, 224, 224, 3]) # Batch input shape.
m.summary()
输出:
2.6.0
0.12.0
Model: "sequential"
_________________________________________________________________
Layer (type) Output Shape Param #
=================================================================
keras_layer_1 (KerasLayer) (None, 2048) 23564800
_________________________________________________________________
dense (Dense) (None, 10) 20490
=================================================================
Total params: 23,585,290
Trainable params: 20,490
Non-trainable params: 23,564,800
_________________________________________________________________