Skip to content

Commit

Permalink
small changes
Browse files Browse the repository at this point in the history
  • Loading branch information
zeptofine committed Oct 9, 2023
1 parent 2a0caa8 commit 10c12d8
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 22 deletions.
10 changes: 6 additions & 4 deletions imdataset_creator/datarules/dataset_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def __init__(self, db_path: Path) -> None:
self.__df = DataFrame(schema=self.basic_schema)

def add_rules(self, *rules: type[Rule] | Rule) -> None:
"""Adds rules to the rule list. Rules will be instantiated separately."""
"""Adds rules to the rule list. Rules can be instantiated separately."""

for rule in rules:
self.add_rule(rule)
Expand Down Expand Up @@ -116,7 +116,7 @@ def add_new_paths(self, pths: set[str]) -> bool:
Parameters
----------
pths : set[os.PathLike]
pths : set[str]
The paths to add to the dataframe.
Returns
Expand Down Expand Up @@ -163,7 +163,7 @@ def remove_unfinished_producers(self) -> ProducerSet:

def unfinished_by_col(self, df: DataFrame, cols: Iterable[str] | None = None) -> DataFrame:
if cols is None:
cols = {*self.type_schema} & set(df.columns)
cols = set(self.type_schema) & set(df.columns)
return df.filter(pl.any_horizontal(pl.col(col).is_null() for col in cols))

def split_files_via_nulls(
Expand Down Expand Up @@ -279,7 +279,9 @@ def __exit__(self, exc_type, exc_value, exc_traceback):
pass

def __repr__(self) -> str:
attrlist: list[str] = [f"{key}={val!r}" for key, val in vars(self).items() if all(k not in key for k in ("__"))]
attrlist: list[str] = [
f"{key}={val!r}" for key, val in vars(self).items() if all(k not in key for k in ("__",))
]
return f"{self.__class__.__name__}({', '.join(attrlist)})"

@overload
Expand Down
2 changes: 1 addition & 1 deletion imdataset_creator/gui/frames.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ def __init__(self, parent=None):
self.addActions([collapse_action, duplicate_action, revert_action])

self._minimumsize = self.size()
self.previous_position = None

self.setup_widget()
self.configure_settings_group()
Expand All @@ -76,7 +77,6 @@ def setup_widget(self):

self.group = QGroupBox()
self.descriptionwidget = QLabel(self.desc, self)
self.setCursor(QCursor(Qt.CursorShape.SizeVerCursor))

self.descriptionwidget.hide()
self.descriptionwidget.setWordWrap(True)
Expand Down
11 changes: 6 additions & 5 deletions imdataset_creator/gui/output_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,9 @@
from typing import Callable

import numpy as np
from PySide6.QtWidgets import (
QDoubleSpinBox,
QLabel,
QSpinBox,
)
from PySide6.QtWidgets import QDoubleSpinBox, QLabel, QSpinBox

from PySide6.QtCore import QRect, QSize, Qt, Signal, Slot
from ..datarules import base_rules, data_rules, image_rules
from ..datarules.base_rules import Filter
from ..image_filters import destroyers, resizer
Expand All @@ -19,6 +16,10 @@ class FilterView(FlowItem):

bound_item: type[Filter]

def __init__(self, parent=None):
super().__init__(parent)
self.setMinimumSize(QSize(self.size().width(), 200))

def get(self):
super().get()

Expand Down
28 changes: 16 additions & 12 deletions imdataset_creator/main.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
# from __future__ import annotations

import json
import logging
import os
from collections.abc import Callable, Iterable
from dataclasses import dataclass
from datetime import datetime
Expand All @@ -15,6 +12,7 @@
import rich.progress as progress
import typer
from polars import DataFrame, concat
from rich import print as rprint
from rich.console import Console
from rich.logging import RichHandler
from rich.progress import Progress
Expand Down Expand Up @@ -45,7 +43,7 @@ def read_image(path: str) -> np.ndarray:
return cv2.imread(path, cv2.IMREAD_UNCHANGED)


def get_outputs(file, outputs: Iterable[Output]):
def get_outputs(file, outputs: Iterable[Output]) -> list[OutputScenario]:
return [
OutputScenario(str(pth), output.filters)
for output in outputs
Expand Down Expand Up @@ -78,8 +76,10 @@ def main(
) -> int:
"""Takes a crap ton of images and creates dataset pairs"""
if not config_path.exists():
log.error(
f"{config_path} does not exist. create it in the gui (imdataset-creator-gui or gui.py) and restart this program."
rprint(
f"{config_path} does not exist."
" create it in the gui ([italic]imdataset-creator-gui[/italic]"
" or [italic]python -m imdataset-creator.gui[/italic]) and restart this program."
)
return 0

Expand Down Expand Up @@ -121,14 +121,15 @@ def main(

# Gather images
images: dict[Path, list[Path]] = {}
resolved: dict[str, File] = {}
count_t = p.add_task("Gathering", total=None)
for folder, lst in gather_images(inputs):
images[folder] = lst
for pth in lst:
resolved[str((folder / pth).resolve())] = File.from_src(folder, pth)

p.update(count_t, advance=len(lst))

resolved: dict[str, File] = {
str((src / pth).resolve()): File.from_src(src, pth) for src, lst in images.items() for pth in lst
}
if diff := sum(map(len, images.values())) - len(resolved):
p.log(f"removed an estimated {diff} conflicting symlinks")

Expand Down Expand Up @@ -195,9 +196,12 @@ def trigger_save(save_timer: datetime, collected: list[DataFrame]) -> tuple[date
if verbose:
p.log(db.df)

filter_t = p.add_task("filtering", total=1)
files: list[File] = [resolved[file] for file in db.filter(set(resolved))]
p.update(filter_t, total=len(files), completed=len(files))
if rules:
filter_t = p.add_task("filtering", total=1)
files: list[File] = [resolved[file] for file in db.filter(set(resolved))]
p.update(filter_t, total=len(files), completed=len(files))
else:
files: list[File] = [resolved[file] for file in resolved]

scenarios = list(parse_files(p.track(files, description="parsing scenarios"), outputs))

Expand Down

0 comments on commit 10c12d8

Please sign in to comment.