-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclassify.py
38 lines (31 loc) · 2.11 KB
/
classify.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
from src.utils.classifier_workflow_service import ClassifierWorkflowService
from src.utils.classifier_config import ClassifierConfig
import argparse
from pathlib import Path
from src.utils.cached_file_list import CachedFileList
parser = argparse.ArgumentParser(description='Use a trained model to classify images in a directory. Normalized versions of the images will be produced if they are not already present')
parser.add_argument('src_path', type=Path,
help='Path of image or directory to augment, or file listing paths if the -l parameter is provided')
parser.add_argument('report_path', type=Path,
help='Path where the CSV report of results should be written')
parser.add_argument('-c', '--config', type=Path,
help='If provided, config will be loaded from this file instead of commandline options')
parser.add_argument('-e', '--extensions', default='tif,tiff,jp2,jpg,jpf,jpx,png',
help='List of comma separated file extensions to filter by when operating on a directory. Default: tif,tiff,jp2,jpg,jpf,jpx,png'),
parser.add_argument('-l', '--file-list', action="store_true",
help='If provided, then the src_path will be treated as a text file containing a list of newline separated paths to normalize.'),
parser.add_argument('-r', '--restart', action="store_true",
help='If provided, then the progress log and CSV report will be discarded and processing will start from the beginning'),
parser.add_argument('--refresh', action="store_true",
help='If provided, then the list of files to process will be refreshed from disk')
args = parser.parse_args()
extensions = { f".{item.strip(' .')}" for item in args.extensions.split(',') }
print(f'Classifying images at path: {args.src_path}')
print(f'For types: {extensions}')
config = ClassifierConfig(path=args.config)
if args.file_list or args.src_path.is_dir():
paths = CachedFileList(args.src_path, extensions, args.refresh)
else:
paths = [args.src_path]
service = ClassifierWorkflowService(config, Path(args.report_path), args.restart)
service.process(paths)