def __init__(self, root_dir): self.imgs = [ os.path.join(root_dir, img) for img in sorted(os.listdir(root_dir)) if os.path.isfile(os.path.join(root_dir, img)) and img.endswith('cnn') ] self.serializer = Serializer()
def parser(): if request.method == 'POST': url = request.form['url'] # TODO: implement url validation params = get_params(url) app_id = params['id'][0] try: ln = params['hl'][0] except KeyError: print('No language specified in url') ln = 'en' print(ln) # TODO: Check language permission = Permissions.query.filter_by(app_id=app_id).first() if permission: output = Serializer.deserialize(permission.permission) return jsonify({'permissions': output}) res = get_sel(app_id, ln) new_permission = Permissions(app_id=app_id, permission=Serializer.serialize(res)) db.session.add(new_permission) db.session.commit() return jsonify({'permissions': res})
class CompressedFiles(Dataset): def __init__(self, root_dir): self.imgs = [ os.path.join(root_dir, img) for img in sorted(os.listdir(root_dir)) if os.path.isfile(os.path.join(root_dir, img)) and img.endswith('cnn') ] self.serializer = Serializer() def __len__(self): return len(self.imgs) def __getitem__(self, idx): img_path = self.imgs[idx] print('parsing', img_path) data = self.serializer.parse(img_path) # print ("SIZE", data.size()) return (data, img_path)
def inf(model, inf_dataloader): model.eval() serializer = Serializer() for idx, (data, filename) in enumerate(inf_dataloader): # print(filename) serializer.set_filename(os.path.join('image_codes_test',os.path.splitext(os.path.basename(filename[0]))[0] + '.cnn')) # print ('filename',filename) print ('%d/%d' % (idx, len(inf_dataloader))) # print ('data.shape',data.size()) # pdb.set_trace() _, _, h, w = data.size() print ('h =',h, 'w =', w) dw = (8 - w % 8) if w % 8 else 0 dh = (8 - h % 8) if h % 8 else 0 print ('dw =',dw, 'dh =', dh) if dw or dh: # print ('padding to multiples of 8!') data = F.pad(data, (dw//2, dw-dw//2, dh//2, dh-dh//2)) inf_input = Variable(data.data, volatile=True) else: inf_input = Variable(data, volatile=True) if opt.use_gpu: inf_input = inf_input.cuda() data_code, imp_code = model(inf_input, need_decode=False) # print ('data',data_code * imp_code) # print ('imp', imp_code) print ('saving', serializer.get_filename()) serializer.serialize(imp_code.data, data_code.data, dw, dh) print ('serialize %d success' % idx) print ('- ' * 20)
def share_users(self): string = Serializer.dict_to_string(self.users) self.pub.send_multipart( [Constants.InternalTopics.users.name.encode(), string.encode()])
def from_broadcast(self, topic, message): if topic == Constants.InternalTopics.rooms.name: self.rooms = Serializer.string_to_array(Room, message)
def share_rooms(self): string = Serializer.array_to_string(self.rooms) self.pub.send_multipart( [Constants.InternalTopics.rooms.name.encode(), string.encode()])
def from_broadcast(self, topic, message): if topic == Constants.InternalTopics.users.name: self.users = Serializer.string_to_dict(User, message) self.update_connected_users()
def from_broadcast(self, topic, message): print(topic) if topic.decode() == Constants.InternalTopics.users.name: self.users = Serializer.string_to_dict(User, message.decode()) self.xpub.send_multipart([topic, message])