zensvi.cv.ClassifierPlaces365¶
- class zensvi.cv.ClassifierPlaces365(device=None, verbosity=1)¶
Bases:
zensvi.cv.classification.base.BaseClassifier
A classifier for identifying places using the Places365 model. The model is from Zhou et al. (2017) (https://github.com/CSAILVision/places365).
- Parameters:
device (str, optional) – The device that the model should be loaded onto. Options are “cpu”, “cuda”, or “mps”. If None, the model tries to use a GPU if available; otherwise, falls back to CPU.
verbosity (int, optional) – Level of verbosity for progress bars. Defaults to 1. 0 = no progress bars, 1 = outer loops only, 2 = all loops.
- classify(dir_input: str | pathlib.Path, dir_image_output: str | pathlib.Path | None = None, dir_summary_output: str | pathlib.Path | None = None, batch_size: int = 1, save_image_options: str = 'cam_image blend_image', save_format: str = 'json csv', csv_format: str = 'long', verbosity: int = None)¶
Classifies images based on scene recognition using the Places365 model.
The output file can be saved in JSON and/or CSV format and will contain the scene categories, scene attributes, and environment type (indoor or outdoor) for each image.
A list of categories can be found at https://github.com/CSAILVision/places365/blob/master/categories_places365.txt and a list of attributes can be found at https://github.com/CSAILVision/places365/blob/master/labels_sunattribute.txt
Scene categories’ values range from 0 to 1, where 1 is the highest probability of the scene category. Scene attributes’ values are the responses of the scene attributes, which are the dot product of the scene attributes’ weight and the features of the image, and higher values indicate a higher presence of the attribute in the image. The environment type is either “indoor” or “outdoor”.
- Parameters:
dir_input – Directory containing input images
dir_image_output – Directory to save output images
dir_summary_output – Directory to save summary output
batch_size – Batch size for inference
save_image_options – Save options for images (“cam_image blend_image”)
save_format – Save format for the output (“json csv”)
csv_format – CSV format for the output (“long” or “wide”)
verbosity (int, optional) – Level of verbosity for progress bars. If None, uses the instance’s verbosity level. 0 = no progress bars, 1 = outer loops only, 2 = all loops.
- Raises:
ValueError – If neither dir_image_output nor dir_summary_output is provided
- property verbosity¶
Property for the verbosity level of progress bars.
- Returns:
verbosity level (0=no progress, 1=outer loops only, 2=all loops)
- Return type:
int