Спасибо за интересную проблему. Я протестировал его как на colab, так и на локальном P C (MacOS 10.15). И выясните, что выходные данные отличаются между tf2.1 (стабильный) и tf2.2 (нестабильный). Возможно, вы могли бы проверить свою версию tf на своем локальном P C, удалить tf2.1, а затем установить ночную версию с pip3 install tf-nightly
.
Я тестирую с помощью приведенного ниже сценария:
import tensorflow as tf
from tensorflow.keras import Sequential, layers
import numpy as np
print(tf.__version__)
model = Sequential()
model.add(layers.Input(shape=(224, 224, 3)))
model.add(layers.Conv2D(filters=64, kernel_size=5, activation="relu", name='conv1'))
model.add(layers.ReLU(name='relu'))
layer_act_op = {layer.name: layer.output for layer in model.layers}
act_model = tf.keras.models.Model(inputs=model.input, outputs=layer_act_op)
data = np.arange(224*224*3*2).reshape(2, 224, 224, 3)
_ = act_model.predict(data)
print(type(_))
print(_.keys())
Выходы:
2.2.0-dev20200429
2020-05-04 09:37:04.953746: I tensorflow/core/platform/cpu_feature_guard.cc:142] This TensorFlow binary is optimized with Intel(R) M
KL-DNN to use the following CPU instructions in performance-critical operations: AVX2 FMA
To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.
2020-05-04 09:37:04.977887: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x7fd8c0626f20 initialized for platform Ho
st (this does not guarantee that XLA will be used). Devices:
2020-05-04 09:37:04.977916: I tensorflow/compiler/xla/service/service.cc:176] StreamExecutor device (0): Host, Default Version
<class 'dict'>
dict_keys(['conv1', 'relu'])