-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathunsw-goannas-scrap.py
67 lines (46 loc) · 1.91 KB
/
unsw-goannas-scrap.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#%% Imports and constants
import os
base_folder = os.path.expanduser('~/data/unsw-alting')
yolo_folder = os.path.join(base_folder,'yolo-training-folder')
labelme_folder = os.path.join(base_folder,'labelme-folders')
assert os.path.isdir(yolo_folder)
assert os.path.isdir(labelme_folder)
#%% Find images in the YOLO and labelme folders
from md_utils.path_utils import find_images
yolo_images = find_images(yolo_folder,return_relative_paths=True,recursive=True)
labelme_images = find_images(labelme_folder,return_relative_paths=True,recursive=True)
print('Found {} images in yolo folder'.format(len(yolo_images)))
print('Found {} images in labelme folder'.format(len(labelme_images)))
#%% See what's in the labelme folder, but not the yolo folder
# YOLO filenames look like:
#
# goanna#BrendanAltingMLDP2023Images#Q25#Q25__2023-01-15__12-41-27(10).JPG
#
# labelme filenames look like:
#
# BrendanAltingMLDP2023Images#Q25#Q25__2023-01-15__12-41-27(10).JPG
yolo_base_filenames = set()
for fn in yolo_images:
bn = fn.split('/')[-1]
assert '#' in bn
bn = '#'.join(bn.split('#')[1:])
yolo_base_filenames.add(bn)
images_not_in_yolo_folder = []
# fn = labelme_images[0]
for fn in labelme_images:
bn = fn.split('/')[-1]
if bn not in yolo_base_filenames:
images_not_in_yolo_folder.append(fn)
print('Found {} files in the labelme folder that are not in the YOLO folder'.format(
len(images_not_in_yolo_folder)))
#%%
from collections import defaultdict
label_to_unused_count = defaultdict(int)
for fn in images_not_in_yolo_folder:
label = fn.split('/')[0]
label_to_unused_count[label] = label_to_unused_count[label] + 1
print('Unused labels:\n')
from md_utils.ct_utils import sort_dictionary_by_value
label_to_unused_count = sort_dictionary_by_value(label_to_unused_count,reverse=True)
for s in label_to_unused_count:
print('{}: {}'.format(s,label_to_unused_count[s]))