8 parser = argparse.ArgumentParser()
14 "Path to the text file which lists the absolute paths of the raw image data files to be converted.",
17 "-o", "--output_path", type=str, help="Path to the output hdf5 file.", required=True)
19 args = parser.parse_args()
20 data_list = args.data_list
21 output_path = args.output_path
24 h5_file = h5.File(output_path, 'w')
25 group = h5_file.create_group("value")
26 # We assume the raw input data have the correct type/shape for the corresponding model
27 # If this flag is set in the hdf5 file, record-minmax will skip type/shape check
28 group.attrs['rawData'] = '1'
30 if os.path.isfile(data_list) == False:
31 raise SystemExit("No such file. " + data_list)
35 with open(data_list, 'r') as f:
39 filename = line.rstrip()
40 if os.path.isfile(filename):
41 datalist.append(filename)
43 raise SystemExit("No such file. " + filename)
47 for imgdata in datalist:
48 with open(imgdata, 'rb') as f:
49 sample = group.create_group(str(num_converted))
51 filename = os.path.basename(imgdata)
52 sample.attrs['desc'] = filename
53 raw_data = bytearray(f.read())
54 # The target model is DNN for handling an input image
55 sample.create_dataset('0', data=raw_data)
59 print("Raw image data have been packaged to " + output_path)
60 print("Number of packaged data: " + str(num_converted))