コード例 #1
0
def trainConstructModel():
    from a_construct_yolo_model import construct_refine_model
    model = construct_refine_model()

    import b_load_model_weights
    b_load_model_weights.load_model_weights(model)
    model.add(Dense(1470))

    images = []
    label = []
    with open("batch_data_6.pkl", 'rb') as handle:
        data = pickle.load(
            handle
        )  # Warning: If adding something here, also modifying saveDataset
        images = data['x']
        label = data['y']

    batch = np.array([
        np.transpose(cv2.resize(image[300:650, 500:, :], (448, 448)),
                     (2, 0, 1)) for image in images
    ])
    batch = 2 * (batch / 255.) - 1

    model.compile(loss='mean_squared_error',
                  optimizer='adadelta',
                  metrics=['accuracy'])

    model.fit(
        batch,
        label,
        batch_size=1,
        nb_epoch=5,  # other is 13 is ok
        verbose=1,
        validation_data=(batch, label))

    # model inference the image
    import d_inference_image

    # # (1) 数据探索
    #  data explore
    imagePath = './test_images/test1.jpg'
    image = plt.imread(imagePath)
    image_crop = image[300:650, 500:, :]
    resized = cv2.resize(image_crop, (448, 448))
    out = d_inference_image.inference_image(model, resized)
    print("test result")
    print(str(out))
    # (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
    import f_visualize_image_car_detection
    f_visualize_image_car_detection.visualize_image_car_detection(boxes)
コード例 #2
0
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()
コード例 #3
0
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
import f_visualize_image_car_detection

f_visualize_image_car_detection.visualize_image_car_detection(boxes)

# (5) 可视化并对多个示例图像进行车辆检测
# Visualize more examples