def send_param(self, param, name): """ 发送参数给引擎 :param name: 图片名 :param param: 捏脸参数 """ shape = utils.curr_roleshape(self.args.path_to_dataset) dic = {"shape": shape, "param": param, "name": name} self._send('p', json.dumps(dic))
def write(self, params): """ 生成二进制文件 能够在unity里还原出来 :param params: 捏脸参数 tensor [batch, 95] """ np_param = params.cpu().detach().numpy() np_param = np_param[0] list_param = np_param.tolist() dataset = self.args.path_to_dataset shape = utils.curr_roleshape(dataset) f = open("../unity/models/eval.bytes", 'wb') write_layer(f, shape, list_param) f.close()
close connect """ if self.open: log.warn("socket close") self._send('q', "-") # quit self.socket.close() self.open = False if __name__ == '__main__': from parse import parser import logging args = parser.parse_args() log.init("FaceNeural", logging.INFO, log_path="./output/log.txt") log.info(utils.curr_roleshape(args.path_to_dataset)) net = Net(args.udp_port, args) while True: r_input = input("command: ") if r_input == "m": net.send_message("hello world") elif r_input == "p": params = utils.random_params(args.params_cnt) net.send_param(params, str(random.randint(1000, 9999))) elif r_input == "q": net.close() break else: log.error("unknown code, quit")