Exemple #1
0
 def on_clients_initialized(self):
     io.progress_bar("Sorting", len(self.img_list))
Exemple #2
0
 def on_clients_initialized(self):
     io.progress_bar("Searching deleted files", len(self.input_paths))
Exemple #3
0
 def on_clients_initialized(self):
     io.progress_bar("Processing", len(self.idx_shapes_list))
Exemple #4
0
 def on_clients_initialized(self):
     io.progress_bar("Sort by hist-dissim", self.yaws_sample_list_len)
Exemple #5
0
    def on_clients_initialized(self):
        if self.debug:
            io.named_window("Debug convert")

        io.progress_bar("Converting", len(self.input_data))
Exemple #6
0
 def on_clients_initialized(self):
     io.progress_bar("", len(self.input_data))
Exemple #7
0
def sort_by_absdiff(input_path):
    io.log_info("Sorting by absolute difference...")

    is_sim = io.input_bool("Sort by similar? ( y/n ?:help skip:y ) : ",
                           True,
                           help_message="Otherwise sort by dissimilar.")

    from nnlib import nnlib
    exec(nnlib.import_all(device_config=nnlib.device.Config()), locals(),
         globals())

    image_paths = Path_utils.get_image_paths(input_path)
    image_paths_len = len(image_paths)

    batch_size = 1024
    batch_size_remain = image_paths_len % batch_size

    i_t = Input((256, 256, 3))
    j_t = Input((256, 256, 3))

    outputs = []
    for i in range(batch_size):
        outputs += [K.sum(K.abs(i_t - j_t[i]), axis=[1, 2, 3])]

    func_bs_full = K.function([i_t, j_t], outputs)

    outputs = []
    for i in range(batch_size_remain):
        outputs += [K.sum(K.abs(i_t - j_t[i]), axis=[1, 2, 3])]

    func_bs_remain = K.function([i_t, j_t], outputs)

    import h5py
    db_file_path = Path(tempfile.gettempdir()) / 'sort_cache.hdf5'
    db_file = h5py.File(str(db_file_path), "w")
    db = db_file.create_dataset("results", (image_paths_len, image_paths_len),
                                compression="gzip")

    pg_len = image_paths_len // batch_size
    if batch_size_remain != 0:
        pg_len += 1

    pg_len = int((pg_len * pg_len - pg_len) / 2 + pg_len)

    io.progress_bar("Computing", pg_len)
    j = 0
    while j < image_paths_len:
        j_images = [cv2_imread(x) for x in image_paths[j:j + batch_size]]
        j_images_len = len(j_images)

        func = func_bs_remain if image_paths_len - j < batch_size else func_bs_full

        i = 0
        while i < image_paths_len:
            if i >= j:
                i_images = [
                    cv2_imread(x) for x in image_paths[i:i + batch_size]
                ]
                i_images_len = len(i_images)
                result = func([i_images, j_images])
                db[j:j + j_images_len, i:i + i_images_len] = np.array(result)
                io.progress_bar_inc(1)

            i += batch_size
        db_file.flush()
        j += batch_size

    io.progress_bar_close()

    next_id = 0
    sorted = [next_id]
    for i in io.progress_bar_generator(range(image_paths_len - 1), "Sorting"):
        id_ar = np.concatenate([db[:next_id, next_id], db[next_id, next_id:]])
        id_ar = np.argsort(id_ar)

        next_id = np.setdiff1d(id_ar, sorted, True)[0 if is_sim else -1]
        sorted += [next_id]
    db_file.close()
    db_file_path.unlink()

    img_list = [(image_paths[x], ) for x in sorted]
    return img_list, []
Exemple #8
0
 def on_clients_initialized(self):
     io.progress_bar("Sort by hist-dissim",
                     len(self.pitch_yaw_sample_list_idxs))
Exemple #9
0
 def on_clients_initialized(self):
     io.progress_bar("Initializing CA weights", len(self.idx_shapes_list))
Exemple #10
0
 def on_clients_initialized(self):
     io.progress_bar("Loading", len(self.image_paths))