-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck_location.py
52 lines (44 loc) · 1.6 KB
/
check_location.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
import os
import json
import numpy as np
from PIL import Image
import h5py
import argparse
from job_combiner import JobCombiner
def show_image(h5_file: str, imclass: str) -> None:
h5_obj = h5py.File(h5_file, 'r+')
imarray = np.array(h5_obj[imclass])
imarray[imarray > 0] = 255
imarray[imarray < 0] = 100
im = Image.fromarray(imarray.astype('uint8'))
im.show()
if __name__ == "__main__":
arg_parse = argparse.ArgumentParser(
description="to show a combined class availability"
)
arg_parse.add_argument('--loc_id', dest="loc_id", required=True,
help="the location id of the image")
arg_parse.add_argument('--class', dest="imclass", required=True,
help="the class of the image that need to be shown")
arg_parse.add_argument('--outpath', dest="outpath", default='output',
help="optionally mention the outpath")
args = arg_parse.parse_args()
h5_file = os.path.join(
args.outpath, args.loc_id, 'combined',
'combined_mask.h5'
)
meta_file = os.path.join(
args.outpath, args.loc_id, 'combined',
'meta.json'
)
if not os.path.exists(h5_file):
raise FileNotFoundError(
"the location id has not combined yet. Please combine before viewing"
)
meta_dict = json.load(open(meta_file))
classes = meta_dict.get('classes')
if args.imclass not in classes:
raise UserWarning(
f"the specified class doesnot exist, please specify from {classes}"
)
show_image(h5_file, args.imclass)