Mat*_*gaj 4 python keras tensorflow
我已经创建了 keras 功能 API 模型,现在我正在尝试研究它的层输出,为从原始模型的输入开始到我选择的层结束的每一层创建子模型。我不明白在没有得到的情况下这样做的正确方法是什么
WARNING:tensorflow:11 out of the last 11 calls to
<function Model.make_predict_function.<locals>.predict_function at 0x7fb8ebc92700>
triggered tf.function retracing.
Tracing is expensive and the excessive number of tracings could be due to (1) creating @tf.function repeatedly
in a loop, (2) passing tensors with different shapes,
(3) passing Python objects instead of tensors.
For (1), please define your @tf.function outside of the loop.
For (2), @tf.function has experimental_relax_shapes=True option that relaxes argument shapes
that can avoid unnecessary retracing.
For (3), please refer to https://www.tensorflow.org/tutorials/customization/performance#python_or_tensor_args
and https://www.tensorflow.org/api_docs/python/tf/function for more details.
Run Code Online (Sandbox Code Playgroud)
我不知道在哪里添加,@tf.function(experimental_relax_shapes=True)因为我没有定义我自己传递给 Keras 的函数
我试图禁用警告但tf.get_logger().setLevel(3)没有成功
这是我收到这条消息的地方:
def extract(layer):
submodel = keras.Model(inputs = model.input, outputs = layer.output)
submodel_output = submodel.predict(np.array(X[random_index]).reshape(1, IMG_SIZE, IMG_SIZE, 3))
for model_layer in model.layers:
extract(model_layer)
Run Code Online (Sandbox Code Playgroud)
如果有办法解决这个问题/禁用警告(优化不是问题)请提前告诉我并感谢您。