def FeatureWriteFC_Bin(name, x): with open('Feature_int8/resnet50/' + name, 'wb') as data: for i in range(x.size(0)): for j in range(x.size(1)): st = x[i][j].item() st = struct.pack('f', st) data.write(st)
def FeatureWriteFC(name, x): with open('Feature_int8/resnet50/' + name, 'w') as data: for i in range(x.size(0)): for j in range(x.size(1)): st = x[i][j].item() st = str(st) data.write(st) data.write('\n')
def FeatureWrite(name, x): with open('Feature_int8/resnet50/' + name + '.txt', 'w') as data: for i in range(x.shape[0]): for j in range(x.shape[1]): for k in range(x.shape[2]): for l in range(x.shape[3]): st = x[i][j][k][l].item() st = str(st) data.write(st) data.write('\n')
def FeatureWrite(name,x): global feature_path if not os.path.exists(feature_path): os.makedirs(feature_path) dim = len(x.shape) if dim == 1: with open(feature_path + '/' +name + '.bin','wb') as data: for i in range(x.shape[0]): st = x[i].item() st = struct.pack('f',st) data.write(st) if dim == 2: with open(feature_path + '/' +name + '.bin','wb') as data: for i in range(x.shape[0]): for j in range(x.shape[1]): st = x[i][j].item() st = struct.pack('f',st) data.write(st) if dim == 3: with open(feature_path + '/' +name + '.bin','wb') as data: for i in range(x.shape[0]): for j in range(x.shape[1]): for k in range(x.shape[2]): st = x[i][j][k].item() st = struct.pack('f',st) data.write(st) if dim == 4: with open(feature_path + '/' +name + '.bin','wb') as data: for i in range(x.shape[0]): for j in range(x.shape[1]): for k in range(x.shape[2]): for l in range(x.shape[3]): st = x[i][j][k][l].item() st = struct.pack('f',st) data.write(st)
def do_POST(self): boundary = self.headers['content-type'].split("=")[1].encode() remaining_bytes = int(self.headers['content-length']) if remaining_bytes <= 0: self.send_response(400) return line = self.rfile.readline() remaining_bytes -= len(line) if not (boundary in line): self.send_response(400) return line = self.rfile.readline() remaining_bytes -= len(line) line = self.rfile.readline() remaining_bytes -= len(line) line = self.rfile.readline() remaining_bytes -= len(line) pre_line = self.rfile.readline() remaining_bytes -= len(pre_line) data = BytesIO() while remaining_bytes > 0: line = self.rfile.readline() remaining_bytes -= len(line) if boundary in line: pre_line = pre_line[0:-1] if pre_line.endswith(b'\r'): pre_line = pre_line[0:-1] data.write(pre_line) data = data.getvalue() input_queue.put((data, bool(self.headers['x-raw']))) print('Added to input queue: ' + str(len(data))) data = output_queue.get() output_queue.task_done() self.send_response(200) self.send_header("Content-Type", "image/png") self.send_header("Content-Length", len(data)) self.end_headers() self.wfile.write(data) return else: data.write(pre_line) pre_line = line self.send_response(400)
new_img, delimiter=",") if (i == 10): l = l + 1 i = 0 print("Csv generation complete.") if args.gen_img: os.makedirs(args.output_dir + '/images', exist_ok=True) files = os.listdir("./" + args.output_dir + '/csv') for f in files: img = np.genfromtxt('./' + args.output_dir + '/csv/' + f, delimiter=',') plt.imshow(img) plt.savefig('./' + args.output_dir + '/images/' + f[:-4] + '.png') files = os.listdir("./" + args.output_dir + "/csv") for f in files: with open('./' + args.output_dir + '/csv/' + f, "r") as data: csv = data.read() csv = csv.split('\n') csv.pop(-1) with open('./' + args.output_dir + '/csv/' + f, "w") as data: csv_data = '' for line in csv: csv_data += '[' + line + '],' csv_data = csv_data[:-1] data.write('[' + csv_data + ']')