我有一批使用labelImg注释的660张图像。我已经将输出xml转换为csv。图像尺寸为1241 * 1754分辨率。
如何传递图像和注释来训练ResNet50进行物体检测?
我有可以检测现实世界对象的模型,但是我对如何传递注释后的图像以保留ResNet的最后一层感到困惑。
model = ResNet50(include_top=False, weights='imagenet', input_shape=(224, 224, 3))
_ = model.output
_ = GlobalAveragePooling2D()(_)
# Fully connected layer
_ = Dense(512, activation='relu')(_)
# Fully connected output/classification layer
predictions = Dense(1, activation='softmax')(_)
model_tl = Model(input=model, output=predictions) ## transfer learning
#Freeze layers
for layer in ResNet50_tl.layers:
layer.trainable = False
model.compile(loss='sparse_categorical_crossentropy',
optimizer='adam',
metrics=['accuracy'])
###########################################################################
from imageai.Detection import ObjectDetection
import os
execution_path = os.getcwd()
detector = ObjectDetection()
detector.setModelTypeAsRetinaNet()
detector.setModelPath( os.path.join(execution_path , "resnet50_coco_best_v2.0.1.h5"))
detector.loadModel()
detections, objects_path = detector.detectObjectsFromImage(input_image=os.path.join(execution_path , "image2.jpg"), output_image_path=os.path.join(execution_path , "image3new.jpg"), minimum_percentage_probability=30, extract_detected_objects=True)
for eachObject, eachObjectPath in zip(detections, objects_path):
print(eachObject["name"] , " : " , eachObject["percentage_probability"], " : ", eachObject["box_points"] )
print("Object's image saved in " + eachObjectPath)
print("--------------------------------")