Esempio n. 1
0
def main():
    ##
    # ext = '.png'
    ## set specific classes
    # class_names = ['bird', 'bottle', 'chair']
    ##

    path, txt_file = process_arguments(sys.argv)

    # remove old files
    clear_class_logs(class_names)

    # get interested classes indexes
    class_ids = get_id_classes(class_names)

    # get from labels image list
    with open(txt_file, "rb") as f:
        i = 0
        for img_name in f:
            # delete white space in prefix and suffix
            img_name = img_name.strip()
            detected_class = contain_class(os.path.join(path, img_name) + ext, class_ids, class_names)

            if detected_class:
                log_class(img_name, detected_class)
                print("No.%d: %s --> detect class: %s" % (i, img_name, detected_class))
            else:
                print("No.%d: %s --> no class" % (i, img_name))
            i += 1
Esempio n. 2
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)
Esempio n. 3
0
def main():
  ##
  preprocess_mode = 'pad'
  im_sz = 500
  class_names = ['bird', 'bottle', 'chair']
  test_ratio = 0.1
  image_ext = '.jpg'
  label_ext = '.png'
  ##

  labels_path, train_list, test_list = process_arguments(sys.argv)
  
  if train_list != None: # all classes in dataset defined using txt files
    class_ids = range(1,21) 
    train_imgs, test_imgs = load_train_test_lists(train_list, test_list)
  else: # only specific class_labels
    class_ids = get_id_classes(class_names)
    train_imgs, test_imgs = split_train_test_imgs(class_names, test_ratio)
    save_test_images(test_imgs)

  shuffle(train_imgs)
  shuffle(test_imgs)

  num_classes = str(len(class_ids))

  ## Train
  # Images
  print('Train images')
  path_src = 'images/'
  path_dst = 'train_images_' + num_classes + '_lmdb'
  convert2lmdb(path_src, train_imgs, image_ext, path_dst, class_ids, preprocess_mode, im_sz, 'image')

  # Labels
  print('Train labels')
  if labels_path:
    path_src = labels_path
  else:
    path_src = 'labels/'

  path_dst = 'train_labels_' + num_classes + '_lmdb'
  convert2lmdb(path_src, train_imgs, label_ext, path_dst, class_ids, preprocess_mode, im_sz, 'label')

  ## Test
  # Images
  print('Test images')
  path_src = 'images/'
  path_dst = 'test_images_' + num_classes + '_lmdb'
  convert2lmdb(path_src, test_imgs, image_ext, path_dst, class_ids, preprocess_mode, im_sz, 'image')

  # Labels
  print('Test labels')
  if labels_path:
    path_src = labels_path
  else:
    path_src = 'labels/'
  path_dst = 'test_labels_' + num_classes + '_lmdb'
  convert2lmdb(path_src, test_imgs, label_ext, path_dst, class_ids, preprocess_mode, im_sz, 'label')
Esempio n. 4
0
def main():
  ## 
  ext = '.png'
  class_names = ['bird', 'bottle', 'chair']
  ## 

  path, txt_file = process_arguments(sys.argv)

  clear_class_logs(class_names)
  class_ids = get_id_classes(class_names)

  with open(txt_file, 'rb') as f:
    for img_name in f:
      img_name = img_name.strip()
      detected_class = contain_class(os.path.join(path, img_name)+ext, class_ids, class_names)

      if detected_class:
        log_class(img_name, detected_class)
Esempio 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)
Esempio n. 6
0
def main():
  ##
  preprocess_mode = 'pad'
  im_sz = 500
  #file_src_images = 'train.txt'
  class_names = ['bird', 'bottle', 'chair']
  test_ratio = 0.1
  ##

  ext = '.png'
  class_ids = get_id_classes(class_names)
  train_imgs, test_imgs = split_train_test_imgs(class_names, ext, test_ratio)

  ## Train
  # Images
  print('Train images')
  path_src = 'images/'
  path_dst = 'train_images_3_lmdb'
  #train_imgs = get_src_imgs(file_src_images, ext)
  convert2lmdb(path_src, train_imgs, path_dst, class_ids, preprocess_mode, im_sz, 'image')

  # Labels
  print('Train labels')
  path_src = 'labels/'
  path_dst = 'train_labels_3_lmdb'
  #train_imgs = get_src_imgs(file_src_images, ext)
  convert2lmdb(path_src, train_imgs, path_dst, class_ids, preprocess_mode, im_sz, 'label')

  ## Test
  # Images
  print('Test images')
  path_src = 'images/'
  path_dst = 'test_images_3_lmdb'
  convert2lmdb(path_src, test_imgs, path_dst, class_ids, preprocess_mode, im_sz, 'image')

  # Labels
  print('Test labels')
  path_src = 'labels/'
  path_dst = 'test_labels_3_lmdb'
  convert2lmdb(path_src, test_imgs, path_dst, class_ids, preprocess_mode, im_sz, 'label')
Esempio n. 7
0
def main():
  labels_path = process_arguments(sys.argv)
  class_ids = get_id_classes(class_names)
  train_imgs, test_imgs = split_train_test_imgs(class_names, test_ratio)

  ## Train
  # Images
  print('Train images')
  path_src = 'images/'
  path_dst = 'train_images_3_lmdb'
  convert2lmdb(path_src, train_imgs, image_ext, path_dst, class_ids, preprocess_mode, im_sz, 'image')

  # Labels
  print('Train labels')
  if labels_path:
    path_src = labels_path
  else:
    path_src = 'labels/'

  path_dst = 'train_labels_3_lmdb'
  convert2lmdb(path_src, train_imgs, label_ext, path_dst, class_ids, preprocess_mode, im_sz, 'label')

  ## Test
  # Images
  print('Test images')
  path_src = 'images/'
  path_dst = 'test_images_3_lmdb'
  convert2lmdb(path_src, test_imgs, image_ext, path_dst, class_ids, preprocess_mode, im_sz, 'image')

  # Labels
  print('Test labels')
  if labels_path:
    path_src = labels_path
  else:
    path_src = 'labels/'
  path_dst = 'test_labels_3_lmdb'
  convert2lmdb(path_src, test_imgs, label_ext, path_dst, class_ids, preprocess_mode, im_sz, 'label')