Exemple #1
0
def show_gtbs(base_dir,
              test_files,
              global_gtbs,
              num_classes,
              cols=1,
              figsize=(12, 8),
              font_size=12):
    orig_images = []
    orig_gtbs = []
    for file in test_files:
        img = load_img(base_dir + file)
        orig_images.append(img)

        gtbs = global_gtbs[file].copy()

        # get rid of is_difficult col (the last one)
        gtbs = gtbs[:, :-1]

        orig_gtbs.append(gtbs)

    show_predictions(orig_images,
                     orig_gtbs,
                     num_classes,
                     cols=cols,
                     conf_threshold=None,
                     figsize=figsize,
                     font_size=font_size)
Exemple #2
0
 def get(self, img_name):
     for img_dir in self.img_dirs:
         img_full_path = os.path.join(img_dir, img_name)
         if os.path.exists(img_full_path):
             img = imaging.load_img(img_full_path).astype(np.float32)
             return img
     raise ValueError("No {} exists in dirs {}".format(
         img_name, self.img_dirs))
Exemple #3
0
def make_prediction(model, target_img_size, base_dir, test_files):
    orig_images = []
    preprocessed_images = []
    for file in test_files:
        img = load_img(base_dir + file)
        orig_images.append(img)
        preprocessed_images.append(preprocess_img(img, target_img_size))

    preprocessed_images = np.array(preprocessed_images)
    y_pred = model.predict(preprocessed_images)
    return orig_images, preprocessed_images, y_pred
Exemple #4
0
def images_to_hdf5(img_dir, hdf5_path, img_files=None, target_img_size=None):
    # datasets/voc/VOCtrainval_06-Nov-2007/JPEGImages
    if not img_files:
        img_files = os.listdir(img_dir)
    print("Found '{}' files in dir '{}'".format(len(img_files), img_dir))

    with h5py.File(hdf5_path, mode='w') as hdf5_file:
        for img_file in img_files:
            img_full_path = os.path.join(img_dir, img_file)
            img = imaging.load_img(img_full_path)
            if target_img_size:
                img = imaging.resize_img(img, target_img_size)
            hdf5_file[img_file] = img.astype(np.uint8)
Exemple #5
0
def images_to_pickle(img_dir,
                     pickle_path,
                     img_files=None,
                     target_img_size=None):
    # datasets/voc/VOCtrainval_06-Nov-2007/JPEGImages
    if not img_files:
        img_files = os.listdir(img_dir)
    print("Found '{}' files in dir '{}'".format(len(img_files), img_dir))

    with open(pickle_path, 'wb') as f:
        data = {}
        for img_file in img_files:
            img_full_path = os.path.join(img_dir, img_file)
            img = imaging.load_img(img_full_path)
            if target_img_size:
                img = imaging.resize_img(img, target_img_size)
            data[img_file] = img.astype(np.uint8)

        pickle.dump(data, f)