Ejemplo n.º 1
0
def main():
  base_dir = 'exper/voc12'
  gpu_id, model_name, iteration_num, phase, subset_dataset = process_arguments(sys.argv)

  if phase == 1:
    model_path = os.path.join(base_dir, 'model', model_name, 'train_iter_{}.caffemodel')
  elif phase == 2:
    model_path = os.path.join(base_dir, 'model', model_name, 'train2_iter_{}.caffemodel')

  if subset_dataset:
    net_path = os.path.join(model_name, 'deploy4.prototxt')
    class_names = ['bird', 'bottle', 'chair'] # CHANGE
    class_ids = get_id_classes(class_names)
    file_names = load_test_data(os.path.join(base_dir, 'list_subset/val_id.txt'))
    images_path = os.path.join(base_dir, 'data/images_orig')
    labels_path = os.path.join(base_dir, 'data/labels_sub_orig')
  else:
    net_path = os.path.join(model_name, 'deploy21.prototxt')
    class_ids = range(1,21)
    file_names = load_test_data(os.path.join(base_dir, 'list/val_id.txt'))
    images_path = os.path.join(base_dir, 'data/images_orig')
    labels_path = os.path.join(base_dir, 'data/labels_orig')

  lut = create_lut(class_ids)
  images, labels = create_full_paths(file_names, images_path, labels_path)
  test_net(net_path, model_path.format(iteration_num), images, labels, lut, gpu_id)
Ejemplo n.º 2
0
def convert2lmdb(path_src, src_imgs, ext, path_dst, class_ids, preprocess_mode,
                 im_sz, data_mode):
    if os.path.isdir(path_dst):
        print('DB ' + path_dst + ' already exists.\n'
              'Skip creating ' + path_dst + '.',
              file=sys.stderr)
        return None

    if data_mode == 'label':
        lut = create_lut(class_ids)

    db = lmdb.open(path_dst, map_size=int(1e12))

    with db.begin(write=True) as in_txn:
        for idx, img_name in enumerate(src_imgs):
            #img = imread(os.path.join(path_src + img_name)+ext)
            img = np.array(Image.open(os.path.join(path_src + img_name) + ext))
            img = img.astype(np.uint8)

            if data_mode == 'label':
                img = preprocess_label(img, lut, preprocess_mode, im_sz)
            elif data_mode == 'image':
                img = preprocess_image(img, preprocess_mode, im_sz)

            img_dat = caffe.io.array_to_datum(img)
            in_txn.put('{:0>10d}'.format(idx), img_dat.SerializeToString())
Ejemplo n.º 3
0
def main():
    iteration_num = process_arguments(sys.argv)

    prototxt = 'TVG_CRFRNN_COCO_VOC_TEST_3_CLASSES.prototxt'
    caffemodel = 'models/train_iter_{}.caffemodel'
    class_names = ['bird', 'bottle', 'chair']
    class_ids = get_id_classes(class_names)
    lut = create_lut(class_ids)

    file_names = load_test_data()
    images, labels = create_full_paths(file_names, 'images', 'labels')

    test_net(prototxt, caffemodel.format(iteration_num), images, labels, lut)
Ejemplo n.º 4
0
def main():
  ## 
  ext = '.png'
  class_names = ['bird', 'bottle', 'chair']
  ## 

  input_path, output_path, list_file, subset_data_file = process_arguments(sys.argv)

  clear_subset_list_logs(subset_data_file)
  class_ids = get_id_classes(class_names)
  lut = create_lut(class_ids)

  with open(list_file, 'rb') as f:
    for img_name in f:
      img_name = img_name.strip()
      img = contain_class(os.path.join(input_path, img_name)+ext, class_ids, lut)

      if img != None:
        log_image(img_name, subset_data_file)
        imsave(os.path.join(output_path, img_name)+ext, img)
Ejemplo n.º 5
0
def main():
    ##
    ext = '.png'
    class_names = ['bird', 'bottle', 'chair']
    ##

    input_path, output_path, list_file, subset_data_file = process_arguments(
        sys.argv)

    clear_subset_list_logs(subset_data_file)
    class_ids = get_id_classes(class_names)
    lut = create_lut(class_ids)

    with open(list_file, 'rb') as f:
        for img_name in f:
            img_name = img_name.strip()
            img = contain_class(
                os.path.join(input_path, img_name) + ext, class_ids, lut)

            if img != None:
                log_image(img_name, subset_data_file)
                imsave(os.path.join(output_path, img_name) + ext, img)
Ejemplo n.º 6
0
def convert2lmdb(path_src, src_imgs, ext, path_dst, class_ids, preprocess_mode, im_sz, data_mode):
  if os.path.isdir(path_dst):
    print('DB ' + path_dst + ' already exists.\n'
          'Skip creating ' + path_dst + '.', file=sys.stderr)
    return None

  if data_mode == 'label':
    lut = create_lut(class_ids)

  db = lmdb.open(path_dst, map_size=int(1e12))

  with db.begin(write=True) as in_txn:
    for idx, img_name in enumerate(src_imgs):
      #img = imread(os.path.join(path_src + img_name)+ext)
      img = np.array(Image.open(os.path.join(path_src + img_name)+ext))
      img = img.astype(np.uint8)

      if data_mode == 'label':
        img = preprocess_label(img, lut, preprocess_mode, im_sz)
      elif data_mode == 'image':
        img = preprocess_image(img, preprocess_mode, im_sz)

      img_dat = caffe.io.array_to_datum(img)
      in_txn.put('{:0>10d}'.format(idx), img_dat.SerializeToString())