def __init__(self): parser = argparse.ArgumentParser( description='PyTorch hand pose Training') args = parser.parse_args() '''user setting''' args.gpu_ids = '0' args.use_net = ['hpe1_orig', 'hpe2'] #hpe1_orig, hig, hpe1, hpe2 forward_list = ['hpe1_orig', 'hpe2'] #hpe1_orig, hig_hpe1, hpe2 trained_modelFile_hpe1_orig = basedir + '..\\HPE\\output\\2020_2_26_11_29\\trainedModel_epoch99.pth.tar' trained_modelFile_hpe2 = basedir + '..\\HPE2\\output\\2020_4_10_18_46\\trainedModel_epoch99.pth.tar' '''common setting''' out_list = {} args.train_net = [] args.cgan = True args.is_train = False args.gan_mode = 'vanilla' args.trainImageSize = 128 trainImageSize = 128 args.skeleton_pca_dim = 52 args.skeleton_orig_dim = 63 args.discriminator_reconstruction = False args.test_batch = 1 hpe_numBlocks = 5 #device #device = torch.device(torch.device("cuda:%s"%args.gpu_ids if torch.cuda.is_available() else "cpu") device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu") args.device = device cudnn.benchmark = True #--HPE_orig net setting if 'hpe1_orig' in args.use_net: if not 'hpe1_orig' in locals(): hpe1_orig = dpnet(args.skeleton_pca_dim, hpe_numBlocks, device) checkpoint = torch.load( trained_modelFile_hpe1_orig, map_location=lambda storage, loc: storage) hpe1_orig.load_state_dict(checkpoint['state_dict']) #--HPE2 net setting if 'hpe2' in args.use_net: if not 'hpe2' in locals(): hpe2 = dpnet(args.skeleton_pca_dim, hpe_numBlocks, device) checkpoint = torch.load( trained_modelFile_hpe2, map_location=lambda storage, loc: storage) hpe2.load_state_dict(checkpoint['state_dict_hpe2']) with open(basedir + '..\\pca_52_by_957032_augmented_X2.pickle', 'rb') as f: self.pca = pickle.load(f) #--fusion net setting #fusionnet=FusionNet(hpe1_orig,pix2pix,hpe1,hpe2,None,args) fl = [] if 'hpe1_orig' in locals(): fl.append(hpe1_orig) else: fl.append(None) if 'pix2pix' in locals(): fl.append(pix2pix) else: fl.append(None) if 'hpe1' in locals(): fl.append(hpe1) else: fl.append(None) if 'hpe2' in locals(): fl.append(hpe2) else: fl.append(None) fusionnet = FusionNet(fl[0], fl[1], fl[2], fl[3], None, args) self.fusionnet = fusionnet.to(device) #--dataset of uvr (for utils) camera_info = {} camera_info['fx'] = 475.065948 camera_info['fy'] = 475.065857 camera_info['cx'] = 315.944855 camera_info['cy'] = 245.287079 camera_info['camerawidth'] = 640 camera_info['cameraheight'] = 480 camera_info['cube'] = np.asarray([250, 250, 250]) camera_info['trainImageSize'] = 128 self.trainImageSize = camera_info['trainImageSize'] self.cube = camera_info['cube'] camerawidth = camera_info['camerawidth'] cameraheight = camera_info['cameraheight'] jointnum = 21 d_maximum = 500 self.datasetloader_uvr = datasetloader_UVR('..', 0, camera_info, '..', '..') self.utils = self.datasetloader_uvr.utils #--start self.fusionnet.set_mode('eval') self.ir_batch = np.zeros( (1, 1, args.trainImageSize, args.trainImageSize), dtype=np.float32) self.depth_batch = np.zeros( (1, 1, args.trainImageSize, args.trainImageSize), dtype=np.float32)
checkpoint = torch.load(trained_modelFile_hpe1_orig, map_location=lambda storage, loc: storage) hpe1_orig.load_state_dict(checkpoint['state_dict']) #--HPE2 net setting if not 'hpe2' in locals(): hpe2 = dpnet(args.skeleton_pca_dim, hpe_numBlocks, device) checkpoint = torch.load(trained_modelFile_hpe2, map_location=lambda storage, loc: storage) hpe2.load_state_dict(checkpoint['state_dict_hpe2']) with open(basedir + '..\\pca_52_by_957032_augmented_X2.pickle', 'rb') as f: pca = pickle.load(f) #--fusion net setting fusionnet = FusionNet(hpe1_orig, pix2pix, hpe1, hpe2, None, args) if 'hpd' in args.use_net: w = np.transpose(pca.components_) b = pca.mean_ fusionnet.set_reconstruction_net(w, b) fusionnet = fusionnet.to(device) #--dataset of uvr (for utils) camera_info = {} if dataset_name == 'v1': camera_info['fx'] = 475.065948 / 2 camera_info['fy'] = 475.065857 / 2 camera_info['cx'] = 315.944855 / 2 camera_info['cy'] = 245.287079 / 2 camera_info['camerawidth'] = 320
hpe1_orig.load_state_dict(checkpoint['state_dict']) #--HPE net setting if not 'hpe1' in locals(): hpe_numBlocks = 5 hpe1 = dpnet(args.skeleton_pca_dim, hpe_numBlocks, device) checkpoint = torch.load(trained_modelFile_hpe1) hpe1.load_state_dict(checkpoint['state_dict']) #--pca with open( "/home/yong/ssd/dataset/HANDS17/training/preprocessed/pca_52_by_957032_augmented_X2.pickle", 'rb') as f: pca = pickle.load(f) #--fusion net setting fusionnet = FusionNet(hpe1_orig, pix2pix, hpe1, None, None, args) fusionnet = fusionnet.to(device) #--camera setting camera_info = {} camera_info['fx'] = 475.065948 camera_info['fy'] = 475.065857 camera_info['cx'] = 315.944855 camera_info['cy'] = 245.287079 camera_info['camerawidth'] = 640 camera_info['cameraheight'] = 480 camera_info['cube'] = np.asarray([250, 250, 250]) camera_info['trainImageSize'] = 128 trainImageSize = camera_info['trainImageSize'] cube = camera_info['cube']
checkpoint = torch.load(trained_modelFile_hpe2) hpe2.load_state_dict(checkpoint['state_dict_hpe2']) else: if not 'hpe2' in locals(): hpe2 = dpnet(args.skeleton_pca_dim, hpe_numBlocks, device) checkpoint = torch.load(trained_modelFile_hpe1_orig) hpe2.load_state_dict(checkpoint['state_dict']) #--pca with open( "/home/yong/ssd/dataset/HANDS17/training/preprocessed/pca_52_by_957032_augmented_X2.pickle", 'rb') as f: pca = pickle.load(f) #--fusion net setting fusionnet = FusionNet(hpe1_orig, None, None, hpe2, None, args) if 'hpd' in args.use_net: w = np.transpose(pca.components_) b = pca.mean_ fusionnet.set_reconstruction_net(w, b) fusionnet = fusionnet.to(device) #--camera setting camera_info = {} camera_info['fx'] = 475.065948 camera_info['fy'] = 475.065857 camera_info['cx'] = 315.944855 camera_info['cy'] = 245.287079 camera_info['camerawidth'] = 640 camera_info['cameraheight'] = 480 camera_info['cube'] = np.asarray([250, 250, 250])
with open(basedir + '..\\pca_52_by_957032_augmented_X2.pickle', 'rb') as f: pca = pickle.load(f) #--fusion net setting #fusionnet=FusionNet(hpe1_orig,pix2pix,hpe1,hpe2,None,args) fl = [] if 'hpe1_orig' in locals(): fl.append(hpe1_orig) else: fl.append(None) if 'pix2pix' in locals(): fl.append(pix2pix) else: fl.append(None) if 'hpe1' in locals(): fl.append(hpe1) else: fl.append(None) if 'hpe2' in locals(): fl.append(hpe2) else: fl.append(None) fusionnet = FusionNet(fl[0], fl[1], fl[2], fl[3], None, args) if 'hpd' in args.use_net: w = np.transpose(pca.components_) b = pca.mean_ fusionnet.set_reconstruction_net(w, b) fusionnet = fusionnet.to(device) ##--init realsense--## if input_type == 'sr300': realsense = Realsense() #pipeline, depth_scale = init_device() #--dataset of uvr (for utils) camera_info = {} camera_info['fx'] = 475.065948