【发布时间】:2021-05-06 07:18:16
【问题描述】:
我希望在应用mask 后检查张量的值。
这是模型的截断部分。我让temp = x 所以稍后我想打印temp 来检查确切的值。
因此,给定一个使用声学特征的 4 类分类模型。假设我在 (1000,50,136) 中有数据作为(批次、时间步长、特征)
目标是检查模型是否按时间步长研究特征。换句话说,我们希望确保模型正在学习使用切片作为图片中的红色矩形。从逻辑上讲,这是Keras LSTM 层的方式,但是当参数更改(例如密集单位)时,产生的confusion matrix 完全不同。验证准确率保持在 45%,因此我们希望将模型可视化。
提出的思路是打印出第一批的第一步,打印出模型中的输入。如果它们相同,则模型以正确的方式学习((136,1) 个特征一次),而不是单个特征的 (50,1) 个时间步长一次。
input_feature = Input(shape=(X_train.shape[1],X_train.shape[2]))
x = Masking(mask_value=0)(input_feature)
temp = x
x = Dense(Dense_unit,kernel_regularizer=l2(dense_reg), activation='relu')(x)
我尝试过tf.print(),它给我带来了AttributeError: 'Tensor' object has no attribute '_datatype_enum'
正如 Lescurel 建议的 Get output from a non final keras model layer。
model2 = Model(inputs=[input_attention, input_feature], outputs=model.get_layer('masking')).output
print(model2.predict(X_test))
AttributeError: 'Masking' object has no attribute 'op'
【问题讨论】:
-
@Lescurel 谢谢,我尝试了该方法,但弹出了一个 AttributeError 。
-
你有一个错字,应该是
model2 = Model(inputs=[input_attention, input_feature], outputs=model.get_layer('masking').output) -
根据您的代码,我猜您想向密集层传递一个带有已删除掩码值的输入。这是不可能的,原因有二。首先,密集层必须具有固定的输入大小。其次,遮罩层不会以任何方式改变输入,它只会附加相应的遮罩(参见tensorflow.org/guide/keras/masking_and_padding#masking)。请同时指定您的全球目标。
标签: python tensorflow machine-learning