loss_train = torch.nn.MSELoss() reduction = 'none' loss_test = losses_poses.MPJPECriterion(weight=1, reduction=reduction) loss_train = losses_poses.StaticDenormalizedLoss(pose_key, loss_train) loss_test = losses_generic.LossLabelMeanStdUnNormalized( pose_key, loss_test, scale_normalized=False) #if config_dict['spatial_transformer_num'] >= 2: # loss_train = losses_poses.MultiPersonSimpleLoss(loss_train) # minimum of two # loss_test = losses_poses.MultiPersonSimpleLoss(loss_test) # minimum of two # annotation and pred is organized as a list, to facilitate multiple output types (e.g. heatmap and 3d loss) return loss_train, loss_test def get_parameter_description(self, config_dict): #, config_dict): folder = "../output/trainPose_{note}_layers{num_encoding_layers}_implR{implicit_rotation}_fg{latent_fg}_3d{skip_background}_ldrop{latent_dropout}_billin{upsampling_bilinear}_fscale{feature_scale}_shuffleFG{shuffle_fg}_shuffle3d{shuffle_3d}_nth{every_nth_frame}_c{active_cameras}_sub{actor_subset}_bs{useCamBatches}_lr{learning_rate}_".format( **config_dict) folder = folder.replace(' ', '').replace('../', '[DOT_SHLASH]').replace( '.', 'o').replace('[DOT_SHLASH]', '../').replace(',', '_') return folder if __name__ == "__main__": config_dict_module = utils_io.loadModule( "configs/config_train_detect_encode_decode_pose.py") config_dict = config_dict_module.config_dict ignite = IgniteTrainPose() ignite.run(config_dict_module.__file__, config_dict)
utils_train.transfer_partial_weights(pretrained_states, network_single.to_pose, submodule=0) # last argument is to remove "network.single" prefix in saved network print("Done loading weights from config_dict['pretrained_posenet_network_path']") return network_single def predict(): #nonlocal output_dict #model.eval() with torch.no_grad(): input_dict_cuda, label_dict_cuda = utils_data.nestedDictToDevice((input_dict, label_dict), device=device) output_dict_cuda = model(input_dict_cuda) output_dict = utils_data.nestedDictToDevice(output_dict_cuda, device='cpu') if __name__ == "__main__": params = param.get_general_params() config_dict_module = utils_io.loadModule("configs/config_test_encodeDecode.py") config_dict = config_dict_module.config_dict config_dict['batch_size_test'] = 2 config_dict['n_hidden_to3Dpose'] = config_dict.get('n_hidden_to3Dpose', 2) # load data device='cuda' data_loader = pickle.load(open('examples/test_set.pickl',"rb")) ex = data_loader[0][0] # load model model = load_network(config_dict) model = model.to(device)
from utils import io as utils_io import os config_dict = utils_io.loadModule( "./configs/config_train_encodeDecode_pose.py").config_dict config_dict['num_workers'] = 0 config_dict['label_types_test'].remove('img_crop') config_dict['label_types_train'].remove('img_crop') config_dict['batch_size_train'] = 1 config_dict['batch_size_test'] = 1 if 0: network_path = '../output/trainNVS_resL3_ResNet_layers4_implRFalse_s3Dp[1_9_11]_w3Dp0_w3D0_wRGB1_wGrad0_wImgNet2_skipBG0_fg128_3dTrue_lh3Dp2_ldrop0o3_billinupper_fscale2_shuffleFGTrue_shuffle3dTrue_h36m_cross_nth1_cFalse_sub[1_5_6_7_8]_bs2_lr0o001_' config_dict[ 'pretrained_network_path'] = network_path + '/models/network_best_val_t1.pth' else: network_path = '../examples' config_dict[ 'pretrained_network_path'] = network_path + '/network_best_val_t1.pth' if not os.path.exists(config_dict['pretrained_network_path']): import urllib.request print("Downloading pre-trained weights, can take a while...") urllib.request.urlretrieve( "http://documents.epfl.ch/groups/c/cv/cvlab-unit/www/data/ECCV2018Rhodin/network_best_val_t1.pth", config_dict['pretrained_network_path']) print("Downloading done.")
from utils import io as utils_io #network_path = '/cvlabdata1/home/rhodin/code/humanposeannotation/python/pytorch_selfsupervised_multiview/output/encode_resL3_ResNet_layers4_implRFalse_s3Dp[1_9_11]_w3Dp0_w3D0_wRGB1_wGrad0_wImgNet2_skipBG0_fg128_3dTrue_lh3Dp2_ldrop0o3_billinupper_fscale2_shuffleFGTrue_shuffle3dTrue_h36m_cross_nth1_cFalse_sub[1_5_6_7_8]_bs2_lr0o001_' if 0: network_path = './output/trainNVS_resL3_ResNet_layers4_implRFalse_s3Dp[1_9_11]_w3Dp0_w3D0_wRGB1_wGrad0_wImgNet2_skipBG0_fg128_3dTrue_lh3Dp2_ldrop0o3_billinupper_fscale2_shuffleFGTrue_shuffle3dTrue_h36m_cross_nth1_cFalse_sub[1_5_6_7_8]_bs2_lr0o001_' config_dict = utils_io.loadModule( network_path + "/config_train_encodeDecode.py").config_dict config_dict[ 'pretrained_network_path'] = network_path + '/models/network_last_val.pth' else: import os config_dict = utils_io.loadModule( "configs/config_train_encodeDecode.py").config_dict config_dict[ 'pretrained_network_path'] = './examples/network_best_val_t1.pth' if not os.path.exists(config_dict['pretrained_network_path']): import urllib.request print("Downloading pre-trained weights, can take a while...") urllib.request.urlretrieve( "http://documents.epfl.ch/groups/c/cv/cvlab-unit/www/data/ECCV2018Rhodin/network_best_val_t1.pth", config_dict['pretrained_network_path']) print("Downloading done.") config_dict['label_types_test'] += ['pose_mean', 'pose_std'] config_dict['label_types_train'] += ['pose_mean', 'pose_std'] config_dict['latent_dropout'] = 0 config_dict['shuffle_fg'] = False config_dict['shuffle_3d'] = False config_dict['actor_subset'] = [1] #config_dict['useCamBatches'] = 0
from utils import io as utils_io import os if 0: config_dict = utils_io.loadModule( "./configs/config_train_detect_encode_decode.py").config_dict network_name = '/network_NVS_best.pth' else: config_dict = utils_io.loadModule( "./configs/config_train_detect_encode_decode_pose.py").config_dict network_name = '/network_pose_best.pth' config_dict['num_workers'] = 0 config_dict['label_types_test'].remove('img') config_dict['label_types_train'].remove('img') config_dict['batch_size_train'] = 4 config_dict['batch_size_test'] = 4 if 0: network_path = '../output/train_detectNVS_resL3_layers4_wRGB1_wGrad0_wImgNet2_fg128_ldrop0o3_billinupper_fscale2_shuffleFGFalse_shuffle3dTrue_nth1_cFalse_subNone_bs2_lr0o001_' config_dict[ 'pretrained_network_path'] = network_path + '/models/network_best_val_t1.pth' else: network_path = '../examples' config_dict['pretrained_network_path'] = network_path + network_name if not os.path.exists(config_dict['pretrained_network_path']): import urllib.request print("Downloading pre-trained weights, can take a while...") urllib.request.urlretrieve( "https://datasets-cvlab.epfl.ch/RhodinCVPR2019/" + network_name, config_dict['pretrained_network_path'])
from utils import io as utils_io import os # FIXME: get this from the config network_path = '/bigdata/dingding/cpsc-533/project/UnsupervisedGeometryAwareRepresentationLearning/output/trainNVS_resL3_ResNet_layers4_implRFalse_w3Dp0_w3D0_wRGB1_wGrad0_wImgNet2_skipBG0_fg128_3dTrue_lh3Dp2_ldrop0o3_billinupper_fscale2_shuffleFGTrue_shuffle3dTrue_h36m_nth100_cFalse_sub[1]_bs2_lr0o001_digitCaps10_caps_channel160_capMaskFalse' config_dict = utils_io.loadModule( os.path.join(network_path, "config_train_encodeDecode.py")).config_dict config_dict['pretrained_network_path'] = os.path.join( network_path, 'models/network_last_val.pth') #network_path = '/cvlabdata1/home/rhodin/code/humanposeannotation/python/pytorch_selfsupervised_multiview/output/encode_resL3_ResNet_layers4_implRFalse_s3Dp[1_9_11]_w3Dp0_w3D0_wRGB1_wGrad0_wImgNet2_skipBG0_fg128_3dTrue_lh3Dp2_ldrop0o3_billinupper_fscale2_shuffleFGTrue_shuffle3dTrue_h36m_cross_nth1_cFalse_sub[1_5_6_7_8]_bs2_lr0o001_' # if 0: # network_path = '../output/trainNVS_resL3_ResNet_layers4_implRFalse_s3Dp[1_9_11]_w3Dp0_w3D0_wRGB1_wGrad0_wImgNet2_skipBG0_fg128_3dTrue_lh3Dp2_ldrop0o3_billinupper_fscale2_shuffleFGTrue_shuffle3dTrue_h36m_cross_nth1_cFalse_sub[1_5_6_7_8]_bs2_lr0o001_' # config_dict = utils_io.loadModule(network_path + "/config_train_encodeDecode.py").config_dict # config_dict['pretrained_network_path'] = network_path + '../models/network_last_val.pth' # else: # import os # config_dict = utils_io.loadModule("configs/config_train_encodeDecode.py").config_dict # config_dict['pretrained_network_path'] = '../examples/network_best_val_t1.pth' # if not os.path.exists(config_dict['pretrained_network_path']): # import urllib.request # print("Downloading pre-trained weights, can take a while...") # urllib.request.urlretrieve("http://documents.epfl.ch/groups/c/cv/cvlab-unit/www/data/ECCV2018Rhodin/network_best_val_t1.pth", # config_dict['pretrained_network_path']) # print("Downloading done.") config_dict['label_types_test'] += ['pose_mean', 'pose_std'] config_dict['label_types_train'] += ['pose_mean', 'pose_std'] config_dict['latent_dropout'] = 0 config_dict['shuffle_fg'] = False
losses_train = [] losses_test = [] if 'img_crop' in config_dict['output_types']: if config_dict['loss_weight_rgb']>0: losses_train.append(image_pixel_loss) losses_test.append(image_pixel_loss) if config_dict['loss_weight_imageNet']>0: losses_train.append(image_imgNet_loss) losses_test.append(image_imgNet_loss) loss_train = losses_generic.PreApplyCriterionListDict(losses_train, sum_losses=True) loss_test = losses_generic.PreApplyCriterionListDict(losses_test, sum_losses=True) # annotation and pred is organized as a list, to facilitate multiple output types (e.g. heatmap and 3d loss) return loss_train, loss_test def get_parameter_description(self, config_dict):#, config_dict): folder = "../output/trainNVS_{note}_{encoderType}_layers{num_encoding_layers}_implR{implicit_rotation}_w3Dp{loss_weight_pose3D}_w3D{loss_weight_3d}_wRGB{loss_weight_rgb}_wGrad{loss_weight_gradient}_wImgNet{loss_weight_imageNet}_skipBG{latent_bg}_fg{latent_fg}_3d{skip_background}_lh3Dp{n_hidden_to3Dpose}_ldrop{latent_dropout}_billin{upsampling_bilinear}_fscale{feature_scale}_shuffleFG{shuffle_fg}_shuffle3d{shuffle_3d}_{training_set}_nth{every_nth_frame}_c{active_cameras}_sub{actor_subset}_bs{useCamBatches}_lr{learning_rate}_digitCaps{num_digit_caps}_caps_channel{num_caps_out_channel}_capMask{caps_masked}".format(**config_dict) folder = folder.replace(' ','').replace('../','[DOT_SHLASH]').replace('.','o').replace('[DOT_SHLASH]','../').replace(',','_') #config_dict['storage_folder'] = folder return folder if __name__ == "__main__": config_dict_module = utils_io.loadModule("config_train_encodeDecode.py") config_dict = config_dict_module.config_dict ignite = IgniteTrainNVS() ignite.run(config_dict_module.__file__, config_dict)