MCPcopy
hub / github.com/idealo/imagededup / encode_images

Method encode_images

imagededup/methods/cnn.py:231–267  ·  view source on GitHub ↗

Generate CNN encodings for all images in a given directory of images. Test. Args: image_dir: Path to the image directory. recursive: Optional, find images recursively in a nested image directory structure, set to False by default. num_enc_workers: Optiona

(
        self,
        image_dir: Union[PurePath, str],
        recursive: Optional[bool] = False,
        num_enc_workers: int = 0,
    )

Source from the content-addressed store, hash-verified

229 )
230
231 def encode_images(
232 self,
233 image_dir: Union[PurePath, str],
234 recursive: Optional[bool] = False,
235 num_enc_workers: int = 0,
236 ) -> Dict:
237 """Generate CNN encodings for all images in a given directory of images. Test.
238
239 Args:
240 image_dir: Path to the image directory.
241 recursive: Optional, find images recursively in a nested image directory structure, set to False by default.
242 num_enc_workers: Optional, number of cpu cores to use for multiprocessing encoding generation (supported only on linux platform), set to 0 by default. 0 disables multiprocessing.
243
244 Returns:
245 dictionary: Contains a mapping of filenames and corresponding numpy array of CNN encodings.
246 Example:
247 ```
248 from imagededup.methods import CNN
249 myencoder = CNN()
250 encoding_map = myencoder.encode_images(image_dir='path/to/image/directory')
251 ```
252 """
253 if isinstance(image_dir, str):
254 image_dir = Path(image_dir)
255
256 if not image_dir.is_dir():
257 raise ValueError("Please provide a valid directory path!")
258
259 if num_enc_workers != 0 and sys.platform != "linux":
260 num_enc_workers = 0
261 self.logger.info(
262 f"Setting num_enc_workers to 0, CNN encoding generation parallelization support available on linux platform .."
263 )
264
265 return self._get_cnn_features_batch(
266 image_dir=image_dir, recursive=recursive, num_workers=num_enc_workers
267 )
268
269 @staticmethod
270 def _check_threshold_bounds(thresh: float) -> None:

Calls 1