Tensorflow 试图在TPU上运行高效网络
通过运行以下命令,尝试在TPU上运行EfficientNetTensorflow 试图在TPU上运行高效网络,tensorflow,keras,tpu,Tensorflow,Keras,Tpu,通过运行以下命令,尝试在TPU上运行EfficientNet effnet = efn.EfficientNetB5(weights='imagenet', include_top=False) # Replace all Batch Normalization layers by Group Normalization layers for i, layer in enumerate(effnet.layers): if "batch_normalization" in layer.
effnet = efn.EfficientNetB5(weights='imagenet', include_top=False)
# Replace all Batch Normalization layers by Group Normalization layers
for i, layer in enumerate(effnet.layers):
if "batch_normalization" in layer.name:
effnet.layers[i] = GroupNormalization(groups=32, axis=-1, epsilon=0.00001)
model = Sequential()
model.add(effnet)
model.add(GlobalAveragePooling2D())
model.add(Dropout(0.5))
model.add(Dense(8, activation=elu))
model.compile(loss='mse', optimizer=RAdam(lr=0.00005), metrics=['mse', 'acc'])
print(model.summary())
model_json = model.to_json()
with open("model_ef7_fn.json", "w") as json_file:
json_file.write(model_json)
tpu_model = tf.contrib.tpu.keras_to_tpu_model(
model,
strategy=tf.contrib.tpu.TPUDistributionStrategy(
tf.contrib.cluster_resolver.TPUClusterResolver(
tpu='grpc://' + os.environ['COLAB_TPU_ADDR'])
)
)
但是我得到了这个错误
值错误:
图层在非批次维度中具有可变形状。TPU模型必须
所有操作都具有恒定的形状
You may have to specify `input_length` for RNN/TimeDistributed layers.
Layer: <keras.engine.training.Model object at 0x7f34e5c06f60>
Input shape: (None, None, None, 3)
Output shape: (None, None, None, 2048)
您可能必须为RNN/TimeDistributed层指定“输入长度”。
图层:
输入形状:(无,无,无,3)
输出形状:(无,无,无,2048)