【发布时间】:2021-08-14 14:03:45
【问题描述】:
我的代码已经运行了好几个月,但今天我意识到它不再运行了。在我的代码中,我只是复制粘贴了这个 keras 代码示例:https://keras.io/examples/vision/image_classification_efficientnet_fine_tuning/#example-efficientnetb0-for-stanford-dogs
所以“我的”代码看起来像这样:
import tensorflow as tf
import keras
from keras.layers import *
from keras import Sequential
from keras.layers.experimental import preprocessing
from keras import layers
from tensorflow.keras.applications import EfficientNetB0
img_augmentation = Sequential(
[
preprocessing.RandomRotation(factor=0.15),
preprocessing.RandomTranslation(height_factor=0.1, width_factor=0.1),
preprocessing.RandomFlip(),
preprocessing.RandomContrast(factor=0.1),
],
name="img_augmentation",
)
inputs = layers.Input(shape=(224, 224, 3))
x = img_augmentation(inputs)
outputs = EfficientNetB0(include_top=True, weights=None, classes=5)(x)
model = tf.keras.Model(inputs, outputs)
model.compile(
optimizer="adam", loss="categorical_crossentropy", metrics=["accuracy"]
)
但是,今天当我在我的 colab 中运行这个单元时,我收到了很多这样的警告:
WARNING:tensorflow:
The following Variables were used a Lambda layer's call (tf.compat.v1.nn.fused_batch_norm_422), but
are not present in its tracked objects:
<tf.Variable 'top_bn/gamma:0' shape=(1280,) dtype=float32>
<tf.Variable 'top_bn/beta:0' shape=(1280,) dtype=float32>
It is possible that this is intended behavior, but it is more likely
an omission. This is a strong indication that this layer should be
formulated as a subclassed Layer rather than a Lambda layer
还有这个错误:
TypeError: Cannot convert a symbolic Keras input/output to a numpy array. This error may indicate that you're trying to pass a symbolic value to a NumPy call, which is not supported. Or, you may be trying to pass Keras symbolic inputs/outputs to a TF API that does not register dispatching, preventing Keras from automatically converting the API call to a lambda layer in the Functional Model.
我认为 google colab 更新了 keras 和 tensorflow,现在它们都是 2.5.0 版本
我怎样才能让我的代码再次工作?
【问题讨论】:
标签: tensorflow keras google-colaboratory transfer-learning