diff --git a/processors/metrics/clarifai_api.py b/processors/metrics/clarifai_api.py index 369f0e5c3..075dfc99f 100644 --- a/processors/metrics/clarifai_api.py +++ b/processors/metrics/clarifai_api.py @@ -46,7 +46,7 @@ def is_compatible_with(cls, module=None, user=None): :param module: Module to determine compatibility with """ - return module.type.startswith("image-downloader") + return module.type.startswith("image-downloader") or module.type == "video-frames" options = { "amount": { @@ -132,7 +132,7 @@ def process(self): send_batch = True if image: - if image.name.startswith("."): + if image.name.startswith(".") or image.suffix in (".json", ".log"): # .metadata.json continue diff --git a/processors/metrics/google_vision_api.py b/processors/metrics/google_vision_api.py index d8bba9d3e..fc4e8290f 100644 --- a/processors/metrics/google_vision_api.py +++ b/processors/metrics/google_vision_api.py @@ -46,7 +46,7 @@ def is_compatible_with(cls, module=None, user=None): :param module: Module to determine compatibility with """ - return module.type.startswith("image-downloader") + return module.type.startswith("image-downloader") or module.type == "video-frames" options = { "amount": { @@ -113,7 +113,7 @@ def process(self): self.dataset.update_status("Annotating image %i/%i" % (done, total)) self.dataset.update_progress(done / total) - if image_file.name.startswith("."): + if image_file.name.startswith(".") or image_file.suffix in (".json", ".log"): self.dataset.log(f"Skipping file {image_file.name}, probably not an image.") continue diff --git a/processors/visualisation/image_wall.py b/processors/visualisation/image_wall.py index e1649aedb..2e0600227 100644 --- a/processors/visualisation/image_wall.py +++ b/processors/visualisation/image_wall.py @@ -8,6 +8,7 @@ from PIL import Image, ImageFile, ImageOps, ImageDraw, UnidentifiedImageError from sklearn.cluster import KMeans +from pathlib import Path from common.lib.helpers import UserInput, convert_to_int from backend.lib.processor import BasicProcessor @@ -53,7 +54,7 @@ def is_compatible_with(cls, module=None, user=None): :param module: Dataset or processor to determine compatibility with """ - return module.type.startswith("image-downloader") + return module.type.startswith("image-downloader") or module.type == "video-frames" @classmethod def get_options(cls, parent_dataset=None, user=None): @@ -152,15 +153,15 @@ def numpy_to_rgb(numpy_array): try: picture = Image.open(str(path)) except UnidentifiedImageError: - self.dataset.update_status("Image %s could not be parsed. Skipping." % path) + self.dataset.update_status(f"File {path.name} could not be parsed. Skipping.") continue - self.dataset.update_status("Analysing %s (%i/%i)" % (path.name, len(dimensions), self.source_dataset.num_rows)) + self.dataset.update_status(f"Analysing {path.name} ({len(dimensions):,}/{self.source_dataset.num_rows:,})") self.dataset.update_progress(len(dimensions) / self.source_dataset.num_rows / 2) # these calculations can take ages for huge images, so resize if it is # larger than the threshold - dimensions[path.name] = (picture.width, picture.height) + dimensions[str(path)] = (picture.width, picture.height) value = 0 if sort_mode not in ("", "random") and (picture.height > sample_max or picture.width > sample_max): @@ -238,9 +239,9 @@ def numpy_to_rgb(numpy_array): # converted to HSV, because RGB does not sort nicely if type(value) is int: - image_colours[path.name] = value + image_colours[str(path)] = value else: - image_colours[path.name] = colorsys.rgb_to_hsv(*value) + image_colours[str(path)] = colorsys.rgb_to_hsv(*value) index += 1 @@ -331,9 +332,9 @@ def numpy_to_rgb(numpy_array): size_y = math.ceil(fitted_pixels / size_x / tile_y) * tile_y else: - raise NotImplementedError("Sizing mode '%s' not implemented" % sizing_mode) + raise NotImplementedError(f"Sizing mode '{sizing_mode}' not implemented") - self.dataset.log("Canvas size is %ix%i" % (size_x, size_y)) + self.dataset.log(f"Canvas size is {size_x}x{size_y}") wall = Image.new("RGBA", (int(size_x), int(size_y))) ImageDraw.floodfill(wall, (0, 0), (255, 255, 255, 0)) # transparent background counter = 0 @@ -345,8 +346,9 @@ def numpy_to_rgb(numpy_array): # now actually putting the images on a wall is relatively trivial for path in sorted_image_files: + path = Path(path) counter += 1 - self.dataset.update_status("Rendering %s (%i/%i) to image wall" % (path, counter, len(sorted_image_files))) + self.dataset.update_status(f"Rendering {path.name} ({counter:,}/{len(sorted_image_files):,}) to image wall") self.dataset.update_progress(0.5 + (counter / len(sorted_image_files) / 2)) picture = Image.open(str(staging_area.joinpath(path)))