def trainConstructModel(): model = construct_refine_model() y_train = keras.utils.to_categorical(train[1], num_classes) y_test = keras.utils.to_categorical(test[1], num_classes) import b_load_model_weights b_load_model_weights.load_model_weights(model) # (1) 数据探索 # data explore import c_visualize_image resized = c_visualize_image.visualize_images() import d_inference_image out = d_inference_image.inference_image(model, resized) # 转换为Channel First batch = np.transpose(resized, (2, 0, 1)) # 将图像转换到-1到1区间 batch = 2 * (batch / 255.) - 1 # 测试单张图片,需要将一个数据转换为数组batch数据 batch = np.expand_dims(batch, axis=0) label = np.expand_dims(out, axis=0) model.compile(loss='mean_squared_error', optimizer='adadelta', metrics=['accuracy']) t = now() model.fit(batch, label, batch_size=batch_size, epochs=1, verbose=1, validation_data=(x_test, y_test)) #construct_yolo_model()
# (0) 构建YOLO实时检测模型 # construct the tiny-yolo model import a_construct_yolo_model model = a_construct_yolo_model.construct_yolo_model() import b_load_model_weights b_load_model_weights.load_model_weights(model) # (1) 数据探索 # data explore import c_visualize_image resized = c_visualize_image.visualize_images() # (2) 图像模型推断 # model inference the image import d_inference_image out = d_inference_image.inference_image(model, resized) # (3) YOLO模型预测结果转换为box坐标 # ineference result convert to box import e_convert_to_box boxes = e_convert_to_box.regression_convert_to_box(out) # (4) 单图像上进行车辆检测 # visualize car detection image results
# (0) 构建YOLO实时检测模型 # construct the tiny-yolo model import a_construct_yolo_model model = a_construct_yolo_model.construct_yolo_model() #model.summary() import b_load_model_weights b_load_model_weights.load_model_weights(model) # (1) 数据探索 # data explore import c_visualize_image resized = c_visualize_image.visualize_images( imagePath='./test_images2/test1.jpg') # (2) 图像模型推断 # model inference the image import d_inference_image out = d_inference_image.inference_image(model, resized) print(out) # (3) YOLO模型预测结果转换为box坐标 # ineference result convert to box import e_convert_to_box boxes = e_convert_to_box.regression_convert_to_box(out, class_num_case=12) # (4) 单图像上进行车辆检测