MCPcopy Create free account
hub / github.com/LuChengTHU/dpm-solver / load_database

Method load_database

examples/stable-diffusion/scripts/knn2img.py:104–121  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

102 return out_data
103
104 def load_database(self):
105
106 print(f'Load saved patch embedding from "{self.database_path}"')
107 file_content = glob.glob(os.path.join(self.database_path, '*.npz'))
108
109 if len(file_content) == 1:
110 self.load_single_file(file_content[0])
111 elif len(file_content) > 1:
112 data = [np.load(f) for f in file_content]
113 prefetched_data = parallel_data_prefetch(self.load_multi_files, data,
114 n_proc=min(len(data), cpu_count()), target_data_type='dict')
115
116 self.database = {key: np.concatenate([od[key] for od in prefetched_data], axis=1)[0] for key in
117 self.database}
118 else:
119 raise ValueError(f'No npz-files in specified path "{self.database_path}" is this directory existing?')
120
121 print(f'Finished loading of retrieval database of length {self.database["embedding"].shape[0]}.')
122
123 def load_retriever(self, version='ViT-L/14', ):
124 model = FrozenClipImageEmbedder(model=version)

Callers 1

__init__Method · 0.95

Calls 2

load_single_fileMethod · 0.95
parallel_data_prefetchFunction · 0.90

Tested by

no test coverage detected