【发布时间】:2022-06-18 03:25:49
【问题描述】:
我想创建正负图像对来训练连体网络。我的连体网络如下所示
def ResNet_model():
baseModel = ResNet50(weights="imagenet", include_top=False,input_tensor=Input(shape=(IMAGE_SIZE, IMAGE_SIZE, 3)))
for layer in baseModel.layers[:165]:
layer.trainable = False
headModel = baseModel.output
headModel = GlobalAveragePooling2D()(headModel)
model = Model(inputs=baseModel.input, outputs=headModel)
return model
featureExtractor = ResNet_model()
imgA = Input(shape=(224, 224, 3))
imgB = Input(shape=(224, 224, 3))
view1_branch = featureExtractor(imgA)
view2_branch = featureExtractor(imgB)
all_features = Concatenate()([view1_branch, view2_branch]) # Lambda(euclidean_distance)([view1_branch, view2_branch]) # #Concatenate()([view1_branch, view2_branch])
hybridModel = Dense(500, activation="relu")(all_features)
hybridModel = Dropout(.3)(hybridModel)
hybridModel = Dense(500, activation="relu")(hybridModel)
hybridModel = Dense(500, activation="relu")(hybridModel)
hybridModel = Dense(500, activation="relu")(hybridModel)
hybridModel = Dropout(.25)(hybridModel)
hybridModel = Dense(500, activation="relu")(hybridModel)
hybridModel = Dense(500, activation="relu")(hybridModel)
hybridModel = Dense(10, activation="softmax")(hybridModel)
final_model = Model(inputs=[imgA,imgB], outputs=hybridModel,name="final_output")
我的文件夹结构如下:
|-- class_folder_a
|-- img_1
|-- img_2
|-- img_3
|-- class_folder_b
|-- img_1
|-- img_2
|-- img_3
到目前为止,我发现了一些代码 here 和 here,其中所有图像都在同一个文件夹中。我如何为我提到的文件夹结构创建图像对(正面:两个图像属于同一类,负面:图像属于不同的类)。任何帮助将不胜感激。
【问题讨论】:
标签: tensorflow keras deep-learning siamese-network imagedatagenerator