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)

    # # (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))

    # 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[0], axis=0)

    model.add(Dense(1470))
Beispiel #2
0
def dumpBatchImage():
    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)
    # more examples
    images = [plt.imread(file) for file in glob.glob('./test_images/*.jpg')]
    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
    out = model.predict(batch)

    with open(os.path.join("batch_data_6.pkl"), 'wb') as handle:
        data = {  # Warning: If adding something here, also modifying loadDataset
            'x': images,
            'y': out
        }
        pickle.dump(data, handle, -1)  # Using the highest protocol available

    with open("batch_data_6.pkl", 'rb') as handle:
        data = pickle.load(
            handle
        )  # Warning: If adding something here, also modifying saveDataset
        batch = data['x']
        label = data['y']
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)
Beispiel #4
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()
Beispiel #5
0
from keras.models import Sequential
from keras.layers.convolutional import Convolution2D, MaxPooling2D
from keras.layers.advanced_activations import LeakyReLU
from keras.layers.core import Flatten, Dense, Activation, Reshape
from utils import load_weights, Box, yolo_net_out_to_car_boxes, draw_box
import pylab

# (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