def main(argv): in_path = '' out_path = '' try: opts, args = getopt.getopt(argv, "hi:o:", []) except getopt.GetoptError: print('packer.py -i <inputpath> -o <outputpath>') sys.exit(2) for opt, arg in opts: if opt == '-h': print('packer.py -i <inputpath> -o <outputpath>') sys.exit() elif opt in ("-i"): in_path = arg elif opt in ("-o"): out_path = arg out_lbl = idx.file(dtype=">u1", datashape=[]) out_img = idx.file(dtype=">u1", datashape=[28, 28]) for file_lbl in os.listdir(in_path): if file_lbl.endswith(".idx1-ubyte"): path_lbl = os.path.join(in_path, file_lbl) path_img = os.path.splitext(path_lbl)[0] + ".idx3-ubyte" out_lbl.append(idx.read(path_lbl).body) out_img.append(idx.read(path_img).body) idx.write(os.path.join(out_path, "lbl.idx1-ubyte"), out_lbl) idx.write(os.path.join(out_path, "img.idx3-ubyte"), out_img) saved = idx.read(os.path.join(out_path, "img.idx3-ubyte")).body print(saved.shape)
def saveSamples(self): img_file = idx.file(dtype=">u1", datashape=[28, 28]) lbl_file = idx.file(dtype=">u1", datashape=[]) frames = [self.frame_1, self.frame_2, self.frame_3, self.frame_4] index = 0 for frame in frames: img = self.get_image(frame) print(img.shape) img_file.append([img]) lbl_file.append([index]) frame.clearCanvas() self.showImage(img, frame) index += 1 str_now = now().strftime("%Y%m%d%H%M%S") idx.write("Survey/samples/%s.idx3-ubyte" % str_now, img_file) idx.write("Survey/samples/%s.idx1-ubyte" % str_now, lbl_file)
def save_parameters(parameters): global mlp_parameters mlp_parameters = parameters import idx idx.write("parameters", utils.square_parameters(parameters[0]))
def save_parameters(parameters): import idx idx.write("parameters", utils.square_parameters(parameters))