%load_ext autoreload
%autoreload 2

get_parser[source]

get_parser()

log_elapsed_time..log..wrapped[source]

log_elapsed_time..log..wrapped(*args, **kwargs)

# $ cd <project root>
# $ make build
# $ pip install -e .
# reload current notebook kernel
! rm -rf /tmp/cococo/json_tree
! cocorepr \
    --in_json_file ../examples/coco_chunk/json_file/instances_train2017_chunk3x2.json \
    --out_path /tmp/cococo/json_tree \
    --out_format json_tree \
    --overwrite
INFO: Arguments: Namespace(debug=False, in_crop_tree=[], in_json_file=[PosixPath('../examples/coco_chunk/json_file/instances_train2017_chunk3x2.json')], in_json_tree=[], indent=4, max_crops_per_class=None, out_format='json_tree', out_path=PosixPath('/tmp/cococo/json_tree'), overwrite=True, seed=42)
INFO: Loading json_file from: ../examples/coco_chunk/json_file/instances_train2017_chunk3x2.json
INFO:   json file loaded: elapsed 0:00:00.000281
INFO:   dataset constructed: elapsed 0:00:00.003357
INFO: Loaded json_file: elapsed 0:00:00.003739: CocoObjectDetectionDataset(images=6, licenses=8, annotations=6, categories=3)
INFO: Dumping json_tree to dir: /tmp/cococo/json_tree
INFO: Dataset written to /tmp/cococo/json_tree: elapsed 0:00:00.001547
INFO: [+] Success: json_tree dumped to /tmp/cococo/json_tree: ['info.json', 'info', 'categories', 'annotations', 'licenses', 'images']
! rm -rf /tmp/cococo/json_tree
! cocorepr \
    --in_json_file ../examples/coco_chunk/json_file/instances_train2017_chunk3x2.json \
    --out_path /tmp/cococo/json_tree \
    --out_format json_tree \
    --overwrite \
    --max_crops_per_class=1
INFO: Arguments: Namespace(debug=False, in_crop_tree=[], in_json_file=[PosixPath('../examples/coco_chunk/json_file/instances_train2017_chunk3x2.json')], in_json_tree=[], indent=4, max_crops_per_class=1, out_format='json_tree', out_path=PosixPath('/tmp/cococo/json_tree'), overwrite=True, seed=42)
INFO: Loading json_file from: ../examples/coco_chunk/json_file/instances_train2017_chunk3x2.json
INFO: Loaded from json_file: CocoObjectDetectionDataset(images=6, licenses=8, annotations=6, categories=3)
INFO: Cutting off crops up to 1 per class, random seed=42
INFO: After cutting off: CocoObjectDetectionDataset(images=3, licenses=8, annotations=3, categories=3)
INFO: Dumping json_tree to dir: /tmp/cococo/json_tree
INFO: [+] Success: json_tree dumped to /tmp/cococo/json_tree: ['info.json', 'info', 'categories', 'annotations', 'licenses', 'images']
! rm -rf /tmp/cococo/json_file
! cocorepr \
    --in_json_tree ../examples/coco_chunk/json_tree \
    --out_path /tmp/cococo/json_file/annotations.json \
    --out_format json_file \
    --indent=None
INFO: Arguments: Namespace(debug=False, in_crop_tree=[], in_json_file=[], in_json_tree=[PosixPath('../examples/coco_chunk/json_tree')], indent=None, max_crops_per_class=None, out_format='json_file', out_path=PosixPath('/tmp/cococo/json_file/annotations.json'), overwrite=False, seed=42)
INFO: Loading json_tree from dir: ../examples/coco_chunk/json_tree
INFO: Loaded from json_tree: CocoObjectDetectionDataset(images=6, licenses=8, annotations=6, categories=3)
INFO: Writing dataset CocoObjectDetectionDataset(images=6, licenses=8, annotations=6, categories=3) to json-file: /tmp/cococo/json_file/annotations.json
INFO: [+] Success: json_file dumped to /tmp/cococo/json_file/annotations.json
! rm -rf /tmp/cococo/crop_tree
! cocorepr \
    --in_json_file ../examples/coco_chunk/json_file/instances_train2017_chunk3x2.json \
    --out_path /tmp/cococo/crop_tree \
    --out_format crop_tree \
    --overwrite
INFO: Arguments: Namespace(debug=False, in_crop_tree=[], in_json_file=[PosixPath('../examples/coco_chunk/json_file/instances_train2017_chunk3x2.json')], in_json_tree=[], indent=4, max_crops_per_class=None, out_format='crop_tree', out_path=PosixPath('/tmp/cococo/crop_tree'), overwrite=True, seed=42)
INFO: Loading json_file from: ../examples/coco_chunk/json_file/instances_train2017_chunk3x2.json
INFO: Loaded from json_file: CocoObjectDetectionDataset(images=6, licenses=8, annotations=6, categories=3)
INFO: Dumping crop_tree to dir: /tmp/cococo/crop_tree
Processing images: 100%|██████████████████████████| 6/6 [00:04<00:00,  1.49it/s]
INFO: [+] Success: crop_tree dumped to /tmp/cococo/crop_tree: ['crops', 'images']
cats = !ls /tmp/cococo/crop_tree/crops
cat = cats[0]
cat
'bicycle--2'
 
crops = !ls /tmp/cococo/crop_tree/crops/{cat}
deleted_crop = crops[0]
deleted_crop
'124710.png'
! ls /tmp/cococo/crop_tree/crops/{cat}
! rm /tmp/cococo/crop_tree/crops/{cat}/{deleted_crop}
! ls /tmp/cococo/crop_tree/crops/{cat}
124710.png  124713.png
124713.png
! rm -rf /tmp/json_tree_2
! cocorepr \
    --in_json_file ../examples/coco_chunk/json_file/instances_train2017_chunk3x2.json \
    --in_crop_tree /tmp/cococo/crop_tree \
    --out_path /tmp/cococo/json_tree_2 \
    --out_format json_tree

! [ ! -f {TMP2}/annotations/{deleted_crop} ] && echo "[+] File successfully not exists"
INFO: Arguments: Namespace(debug=False, in_crop_tree=PosixPath('/tmp/cococo/crop_tree'), in_json_files=[PosixPath('../examples/coco_chunk/json_file/instances_train2017_chunk3x2.json')], in_json_trees=[], indent=4, out_format='json_tree', out_path=PosixPath('/tmp/cococo/json_tree_2'), overwrite=False)
INFO: Loading json file from file: ../examples/coco_chunk/json_file/instances_train2017_chunk3x2.json
INFO: Loaded: images=6, annotations=6, categories=3
INFO: Loading blob list from dir: /tmp/cococo/crop_tree
INFO: Loaded crop tree: len(annotations)=5 len(images)=5 len(categories)=3
INFO: Dumping json tree to dir: /tmp/cococo/json_tree_2
Traceback (most recent call last):
  File "/home/ay/.pyenv/versions/3.7.6/bin/cocorepr", line 33, in <module>
    sys.exit(load_entry_point('cocorepr', 'console_scripts', 'cocorepr')())
  File "/plain/github/nm/cocorepr/cocorepr/main.py", line 81, in main
    dump_fun(coco, out_path, skip_nulls=True, overwrite=overwrite, indent=indent)
  File "/plain/github/nm/cocorepr/cocorepr/json_tree.py", line 78, in dump_json_tree
    raise ValueError(f"Destination json tree dir already exists: {target_dir}")
ValueError: Destination json tree dir already exists: /tmp/cococo/json_tree_2
[+] File successfully not exists
! rm -rf /tmp/cococo/crop_tree_2
! cocorepr \
    --in_json_tree /tmp/cococo/json_tree_2 \
    --in_crop_tree /tmp/cococo/crop_tree \
    --out_path /tmp/cococo/crop_tree_2 \
    --out_format crop_tree
! ls /tmp/cococo/crop_tree_2 | grep crops
INFO: Arguments: Namespace(debug=False, in_crop_tree=PosixPath('/tmp/cococo/crop_tree'), in_json_files=[], in_json_trees=[PosixPath('/tmp/cococo/json_tree_2')], indent=4, out_format='crop_tree', out_path=PosixPath('/tmp/cococo/crop_tree_2'), overwrite=False)
INFO: Loading json tree from dir: /tmp/cococo/json_tree_2
INFO: Loading blob list from dir: /tmp/cococo/crop_tree
INFO: Loaded crop tree: len(annotations)=5 len(images)=5 len(categories)=3
INFO: Dumping crop tree to dir: /tmp/cococo/crop_tree_2
Processing images: 100%|██████████████████████████| 5/5 [00:04<00:00,  1.20it/s]
INFO: [+] Success: crop_tree dumped to /tmp/cococo/crop_tree_2: ['crops', 'images']
crops
! rm -rf /tmp/cococo/json_file_2
! cocorepr \
    --in_json_tree /tmp/cococo/json_tree_2 \
    --in_crop_tree /tmp/cococo/crop_tree \
    --out_path /tmp/cococo/json_file_2/annotations.json \
    --out_format json_file

! ls /tmp/cococo/json_file_2/annotations.json
INFO: Arguments: Namespace(debug=False, in_crop_tree=PosixPath('/tmp/cococo/crop_tree'), in_json_files=[], in_json_trees=[PosixPath('/tmp/cococo/json_tree_2')], indent=4, out_format='json_file', out_path=PosixPath('/tmp/cococo/json_file_2/annotations.json'), overwrite=False)
INFO: Loading json tree from dir: /tmp/cococo/json_tree_2
INFO: Loading blob list from dir: /tmp/cococo/crop_tree
INFO: Loaded crop tree: len(annotations)=5 len(images)=5 len(categories)=3
INFO: Dumping json file to file: /tmp/cococo/json_file_2/annotations.json
INFO: Writing dataset to json file: /tmp/cococo/json_file_2/annotations.json
INFO: [+] Success: json_file dumped to /tmp/cococo/json_file_2/annotations.json
/tmp/cococo/json_file_2/annotations.json
! rm -rf /tmp/cococo/json_file_3/
! cocorepr \
    --in_json_tree /tmp/cococo/json_tree_2 \
    --in_json_file /tmp/cococo/json_file/annotations.json \
    --out_path /tmp/cococo/json_file_3/annotations.json \
    --out_format json_file \
    --overwrite
INFO: Arguments: Namespace(debug=False, in_crop_tree=None, in_json_files=[PosixPath('/tmp/cococo/json_file/annotations.json')], in_json_trees=[PosixPath('/tmp/cococo/json_tree_2')], indent=4, out_format='json_file', out_path=PosixPath('/tmp/cococo/json_file_3/annotations.json'), overwrite=True)
INFO: Loading json tree from dir: /tmp/cococo/json_tree_2
INFO: Loading json file from file: /tmp/cococo/json_file/annotations.json
INFO: Loaded: images=6, annotations=6, categories=3
INFO: Dumping json file to file: /tmp/cococo/json_file_3/annotations.json
INFO: Writing dataset to json file: /tmp/cococo/json_file_3/annotations.json
INFO: [+] Success: json_file dumped to /tmp/cococo/json_file_3/annotations.json