我是深度学习的新手。我的代码中发生了什么 我将发布代码和错误 我想做resnet +三重损失
ValueError:尺寸必须相等,但输入形状为[?,2,1],[?, 0,1]的'loss / dropout_1_loss / sub'(op:'Sub')的尺寸必须为2和0。
# define model -----------------------------------------
input_dim = X1.shape[1:]
#print(input_dim)
input_a = Input(shape=input_dim) # <class 'tensorflow.python.framework.ops.Tensor'>
input_b = Input(shape=input_dim)
input_c = Input(shape=input_dim)
model_a = resnet50.ResNet50(weights="imagenet", include_top=True, input_tensor=input_a)
model_b = resnet50.ResNet50(weights="imagenet", include_top=True, input_tensor=input_b)
model_c = resnet50.ResNet50(weights="imagenet", include_top=True, input_tensor=input_c)
for layer in model_a.layers:
if(layer.name != 'fc1000'):
layer.trainable = False
layer.name = layer.name + "_1"
for layer in model_b.layers:
if(layer.name != 'fc1000'):
layer.trainable = False
layer.name = layer.name + "_2"
for layer in model_c.layers:
if(layer.name != 'fc1000'):
layer.trainable = False
layer.name = layer.name + "_3"
shared_fc1000 = model_a.get_layer('fc1000_1')
# weight transfer
a = model_a.get_layer('avg_pool_1').output
b = model_b.get_layer('avg_pool_2').output
c = model_c.get_layer('avg_pool_3').output
processed_a = shared_fc1000(a)
processed_b = shared_fc1000(b)
processed_c = shared_fc1000(c)
positive_dist = Lambda(euclidean_distance, output_shape=eucl_dist_output_shape)([processed_a, processed_b])
negative_dist = Lambda(euclidean_distance, output_shape=eucl_dist_output_shape)([processed_a, processed_c])
stacked_dists = Lambda(
lambda vects: K.stack(vects, axis=1),
output_shape=eucl_dist_output_shape
)([positive_dist, negative_dist])
model = Model([input_a, input_b, input_c], output=Dropout(0.25)(stacked_dists))
model.summary()
rms = RMSprop()
model.compile(loss=triplet_loss, optimizer=rms)