Ejemplo n.º 1
0
def StartTrain():
    loader = load.Loader()
    batch = cfg.BATCH_SIZE
    if cfg.SPECIFIC_DATA != "":
        loader.load_specific_label(cfg.SPECIFIC_DATA)
        batch = 1
    else:
        loader.load_data()

    nc = NetworkCreator(batch)
    nc.train(loader)
Ejemplo n.º 2
0
def scale_box_size():
    loader = load.Loader()
    loader.load_data()

    bound_above_2, bound_below_2, _ = GetObjectBounds(2, 0.3, 0.33, 2)
    bound_above_4, bound_below_4, _ = GetObjectBounds(2, 0.3, 0.33, 4)
    bound_above_8, bound_below_8, _ = GetObjectBounds(2, 0.3, 0.33, 8)
    bound_above_16, bound_below_16, _ = GetObjectBounds(2, 0.3, 0.33, 16)

    heights_scale_2 = []
    heights_scale_4 = []
    heights_scale_8 = []
    heights_scale_16 = []

    for im_model in loader.Data:
        for label in im_model.labels:
            if label.largest_dim >= bound_below_2 and label.largest_dim <= bound_above_2:
                dist = np.abs(label.fbl_y - label.ftl_y)
                heights_scale_2.append(dist)
            if label.largest_dim >= bound_below_4 and label.largest_dim <= bound_above_4:
                dist = np.abs(label.fbl_y - label.ftl_y)
                heights_scale_4.append(dist)
            if label.largest_dim >= bound_below_8 and label.largest_dim <= bound_above_8:
                dist = np.abs(label.fbl_y - label.ftl_y)
                heights_scale_8.append(dist)
            if label.largest_dim >= bound_below_16 and label.largest_dim <= bound_above_16:
                dist = np.abs(label.fbl_y - label.ftl_y)
                heights_scale_16.append(dist)

    _min = np.mean(heights_scale_2) - 2 * np.std(heights_scale_2)
    _max = np.mean(heights_scale_2) + 2 * np.std(heights_scale_2)
    print("heights 2 min:", _min, " max:", _max)

    _min = 0
    _max = 0
    _min = np.mean(heights_scale_4) - 2 * np.std(heights_scale_4)
    _max = np.mean(heights_scale_4) + 2 * np.std(heights_scale_4)
    print("heights 4 min:", _min, " max:", _max)

    _min = 0
    _max = 0
    _min = np.mean(heights_scale_8) - 2 * np.std(heights_scale_8)
    _max = np.mean(heights_scale_8) + 2 * np.std(heights_scale_8)
    print("heights 8 min:", _min, " max:", _max)

    _min = 0
    _max = 0
    _min = np.mean(heights_scale_16) - 2 * np.std(heights_scale_16)
    _max = np.mean(heights_scale_16) + 2 * np.std(heights_scale_16)
    print("heights 16 min:", _min, " max:", _max)
Ejemplo n.º 3
0
def start_test():

    if cfg.SPECIFIC_TEST_DATA == "":
        print("Test data not specified!!! Check config file")
        return

    loader = load.Loader()

    loader.load_specific_label(cfg.SPECIFIC_TEST_DATA)
    loader.prepare_data(1)

    new_saver = tf.train.import_meta_graph(cfg.MODEL_PATH + '.meta',
                                           clear_devices=True)
    graph = tf.get_default_graph()
    input_graph_def = graph.as_graph_def()

    with tf.Session() as sess:

        new_saver.restore(sess, cfg.MODEL_PATH)

        graph = tf.get_default_graph()
        image_placeholder = graph.get_tensor_by_name(
            "input_image_placeholder:0")

        predict_2 = graph.get_tensor_by_name("scale_2/output2/Conv2D:0")
        predict_4 = graph.get_tensor_by_name("scale_4/output4/Conv2D:0")
        predict_8 = graph.get_tensor_by_name("scale_8/output8/Conv2D:0")
        predict_16 = graph.get_tensor_by_name("scale_16/output16/Conv2D:0")

        image_batch, label_batch, image_paths, image_names, calib_matrices = loader.get_test_data(
            1)

        response_maps_2, response_maps_4, response_maps_8, response_maps_16 = sess.run(
            [predict_2, predict_4, predict_8, predict_16],
            feed_dict={image_placeholder: image_batch})
        save_results(response_maps_2, 2)
        save_results(response_maps_4, 4)
        save_results(response_maps_8, 8)
        save_results(response_maps_16, 16)

        extract_and_show(response_maps_2, response_maps_4, response_maps_8,
                         response_maps_16, label_batch, calib_matrices,
                         image_paths)
Ejemplo n.º 4
0
    data = np.asarray([w_fbl, w_fbr, w_rbl, w_rbr, w_ftl, w_ftr, w_rtl, w_rtr])
    transposed = np.squeeze(data.transpose())

    data = np.ones((4, 8))
    data[0:3, 0:8] = transposed
    points = world_space_to_image(data, calib_matrix)

    box = BoxModel()
    box.fbl = (int(points[0, 0]), int(points[1, 0]))
    box.fbr = (int(points[0, 1]), int(points[1, 1]))
    box.rbl = (int(points[0, 2]), int(points[1, 2]))
    box.rbr = (int(points[0, 3]), int(points[1, 3]))
    box.ftl = (int(points[0, 4]), int(points[1, 4]))
    box.ftr = (int(points[0, 5]), int(points[1, 5]))
    box.rtl = (int(points[0, 6]), int(points[1, 6]))
    box.rtr = (int(points[0, 7]), int(points[1, 7]))

    image_model.boxes.append(box)
    return image_model


if __name__ == "__main__":
    loader = load.Loader()
    # loader.load_data()
    loader.load_specific_label("000046")
    image_batch, label_batch, image_paths, calib_matrices = loader.get_test_data(
        1)
    b_boxes_model = test_projection(label_batch[0][1], calib_matrices)
    b_boxes_model.file_name = image_paths[0]
    drawer.draw_bounding_boxes(b_boxes_model)
Ejemplo n.º 5
0
def test_target_map_creation(name):
    loader = load.Loader()
    loader.load_specific_label(name)

    label = tf.placeholder(tf.float32,(None,None,10), name="label")

    target = tf.py_func(create_target_response_map, [label[0], 128, 64, 8, 2,0.3, 0.33, 2], [tf.float32])
    target2 = tf.reshape(target,(8,64,128))
    
    tmp = tf.py_func(create_target_response_map, [label[0], 64, 32, 8, 2,0.3, 0.33, 4], [tf.float32])
    target4 = tf.reshape(tmp,(8,32,64)) 
    
    tmp = tf.py_func(create_target_response_map, [label[0], 32, 16, 8, 2,0.3, 0.33, 8], [tf.float32])
    target8 = tf.reshape(tmp,(8,16,32)) 
    
    tmp = tf.py_func(create_target_response_map, [label[0], 16, 8, 8, 2,0.3, 0.33, 16], [tf.float32])
    target16 = tf.reshape(tmp,(8,8,16)) 
    
    initial = tf.Variable(tf.zeros_like(target2[0,:, :]),dtype=tf.float32, name="initial")
    tmp_initial = initial
    condition = tf.greater(target2[0,:, :], tf.constant(0,dtype=tf.float32),name="greater")
    weight_factor_array = initial.assign( tf.where(condition, (tmp_initial + 2.0), tmp_initial, name="where_condition"), name="assign" )
    
    
    init = tf.global_variables_initializer()
    errors = [2.0,2.0]
    
    loss_output = tf.placeholder(dtype=tf.float32,shape=(2),name='loss_output_placeholder')
    loss_constant = tf.constant(1.0,shape=[2],dtype=tf.float32,name='loss_constant')
    loss_output = tf.multiply(errors,loss_constant, name='loss_output_multiply')
    

    image_batch, labels_batch, image_paths,image_names, calib_matrices = loader.get_test_data(1)
    
    # maps = create_target_response_map(labels_batch[0], 128, 64, 8, 2,0.3, 0.33, 4)
    # print(maps.shape)
    # tmp = h.change_first_x_last_dim(maps)
    
    # cv2.imshow("target 1", maps[0,:,:])
    # cv2.imshow("target 2", maps[1,:,:])
    # cv2.imshow("target 3", maps[2,:,:])
    # cv2.imshow("target 4", maps[3,:,:])
    # cv2.imshow("target 5", maps[4,:,:])
    # cv2.imshow("target 6", maps[5,:,:])
    # cv2.imshow("target 7", maps[6,:,:])
    # cv2.imshow("target 8", maps[7,:,:])
    
    # cv2.imshow("target 11", tmp[:,:,0])
    # cv2.imshow("target 22", tmp[:,:,1])
    # cv2.imshow("target 33", tmp[:,:,2])
    # cv2.imshow("target 44", tmp[:,:,3])
    # cv2.imshow("target 55", tmp[:,:,4])
    # cv2.imshow("target 66", tmp[:,:,5])
    # cv2.imshow("target 77", tmp[:,:,6])
    # cv2.imshow("target 88", tmp[:,:,7])
    
    # cv2.waitKey(0)
                
    #         cv2.waitKey(0)
    # tmp = np.reshape(maps,(8,16,8))
    # print(tmp)
    with tf.Session() as session:
        # initialise the variables

        session.run(init)

        tmp,weight = session.run([target2,weight_factor_array], feed_dict={label: labels_batch})
        maps = h.change_first_x_last_dim(tmp)
        cv2.imshow("target 2", maps[:,:,0])
        cv2.imshow("weights", weight*127)
        cv2.waitKey(0)

        cv2.imwrite(r'C:\Users\Lukas\Documents\Object detection\test\target2.jpg', 255*maps[:,:,0])
        resized = cv2.resize(maps[:,:,0], (1242,375), interpolation = cv2.INTER_AREA)
        cv2.imshow("resized", resized)
        cv2.imwrite(r'C:\Users\Lukas\Documents\Object detection\test\resized2.jpg', 255*resized)
        # cv2.imshow("target 2", maps[:,:,1])
        # cv2.imshow("target 3", maps[:,:,2])
        # cv2.imshow("target 4", maps[:,:,3])
        # cv2.imshow("target 5", maps[:,:,4])
        # cv2.imshow("target 6", maps[:,:,5])
        # cv2.imshow("target 7", maps[:,:,6])
        # cv2.imshow("target 8", maps[:,:,7])
               
        tmp2 = session.run(target4, feed_dict={label: labels_batch})
        maps = h.change_first_x_last_dim(tmp2)
        cv2.imshow("target 4", maps[:,:,0])
        cv2.imwrite(r'C:\Users\Lukas\Documents\Object detection\test\target4.jpg', 255*maps[:,:,0])
        resized4 = cv2.resize(maps[:,:,0], (1242,375), interpolation = cv2.INTER_AREA)
        cv2.imshow("resized4", resized4)
        cv2.imwrite(r'C:\Users\Lukas\Documents\Object detection\test\resized4.jpg', 255*resized4)

        
        tmp4 = session.run(target8, feed_dict={label: labels_batch})
        maps = h.change_first_x_last_dim(tmp4)
        cv2.imshow("target 8", maps[:,:,0])
        cv2.imwrite(r'C:\Users\Lukas\Documents\Object detection\test\target8.jpg', 255*maps[:,:,0])
        resized8 = cv2.resize(maps[:,:,0], (1242,375), interpolation = cv2.INTER_AREA)
        cv2.imshow("resized8", resized8)
        cv2.imwrite(r'C:\Users\Lukas\Documents\Object detection\test\resized8.jpg', 255*resized8)

                
        tmp8 = session.run(target16, feed_dict={label: labels_batch})
        maps = h.change_first_x_last_dim(tmp8)
        cv2.imshow("target 16", maps[:,:,0])
        cv2.imwrite(r'C:\Users\Lukas\Documents\Object detection\test\target16.jpg', 255*maps[:,:,0])
        resized16 = cv2.resize(maps[:,:,0], (1242,375), interpolation = cv2.INTER_AREA)
        cv2.imshow("resized6", resized16)
        cv2.imwrite(r'C:\Users\Lukas\Documents\Object detection\test\resized16.jpg', 255*resized16)

            
        cv2.waitKey(0)