def convert(self, sequence): """convert NYU sequence""" config = sequence.config name = '{}/{}_{}.h5'.format(self.cacheDir, self.datasetName, sequence.name) if os.path.isfile(name): print '{} exist, please check if h5 is right!'.format(name) return Dataset = NYUDataset([sequence]) dpt, gt3D = Dataset.imgStackDepthOnly(sequence.name) depth = [] gtorig = [] gtcrop = [] T = [] gt3Dorig = [] gt3Dcrop = [] com = [] fileName = [] for i in xrange(len(sequence.data)): data = sequence.data[i] depth.append(data.dpt) gtorig.append(data.gtorig) gtcrop.append(data.gtcrop) T.append(data.T) gt3Dorig.append(data.gt3Dorig) gt3Dcrop.append(data.gt3Dcrop) com.append(data.com) fileName.append(int(data.fileName[-11:-4])) dataset = h5py.File(name, 'w') dataset['com'] = np.asarray(com) dataset['inds'] = np.asarray(fileName) dataset['config'] = config['cube'] dataset['depth'] = np.asarray(dpt) dataset['joint'] = np.asarray(gt3D) dataset['gt3Dorig'] = np.asarray(gt3Dorig) dataset.close()
def convert(self, sequence, size_before=None): """convert sequence data""" config = sequence.config if self.name == 'NYU': Dataset = NYUDataset([sequence]) elif self.name == 'ICVL': Dataset = ICVLDataset([sequence]) dpt, gt3D = Dataset.imgStackDepthOnly(sequence.name) dataset = {} com = [] fileName = [] dpt3D = [] size = len(sequence.data) print('size of {} {} dataset is {}'.format(self.name, sequence.name, size)) for i in xrange(len(sequence.data)): data = sequence.data[i] com.append(data.com) dpt3D.append(data.dpt3D) if self.name == 'NYU': fileName.append(int(data.fileName[-11:-4])) elif self.name == 'ICVL' and size_before is not None: fileName.append(int(data.fileName[(data.fileName.find('image_') + 6): \ (data.fileName.find('.png'))]) + size_before) else: fileName.append(int(data.fileName[(data.fileName.find('image_') + 6): \ (data.fileName.find('.png'))])) dataset['depth'] = np.asarray(dpt) dataset['dpt3D'] = np.asarray(dpt3D) dataset['com'] = np.asarray(com) dataset['inds'] = np.asarray(fileName) dataset['config'] = np.asarray(config['cube']).reshape( 1, self.dim).repeat(size, axis=0) dataset['joint'] = np.asarray(gt3D) return dataset
max_error = max_euclidian_joints(vector_max) ff_error = number_frames_within_dist(vector_ff) return euclidian_distance, max_error, ff_error if __name__ == '__main__': global gpu_id dataset = 'test' di = NYUImporter('../../DeepPrior/data/NYU') #datadir = '../../DeepPrior/src/data' #di = NYUImporter(datadir) Seq = di.loadSequence(dataset) testSeqs = [Seq] testDataset = NYUDataset(testSeqs) use_gpu = True gpu_id = 0 if use_gpu: xp = cuda.cupy else: xp = np J = 14 X_test, Y_test = testDataset.imgStackDepthOnly(dataset) Y_test = xp.reshape(Y_test, (Y_test.shape[0], Y_test.shape[1] * Y_test.shape[2])) np.random.seed(0) beta = 1.0 seed = 0 alpha = 0 #0.5 C = 1e-3
print("create data") aug_modes = ['com', 'rot', 'none'] # 'sc', comref = None # "./eval/NYU_COM_AUGMENT/net_NYU_COM_AUGMENT.pkl" docom = False di = NYUImporter('../data/NYU/', refineNet=comref) Seq1 = di.loadSequence('train', shuffle=True, rng=rng, docom=docom) trainSeqs = [Seq1] Seq2_1 = di.loadSequence('test_1', docom=docom) Seq2_2 = di.loadSequence('test_2', docom=docom) testSeqs = [Seq2_1, Seq2_2] # create training data trainDataSet = NYUDataset(trainSeqs) train_data, train_gt3D = trainDataSet.imgStackDepthOnly('train') train_data_cube = numpy.asarray([Seq1.config['cube']] * train_data.shape[0], dtype='float32') train_data_com = numpy.asarray([d.com for d in Seq1.data], dtype='float32') train_gt3Dcrop = numpy.asarray([d.gt3Dcrop for d in Seq1.data], dtype='float32') mb = (train_data.nbytes) / (1024 * 1024) print("data size: {}Mb".format(mb)) valDataSet = NYUDataset(testSeqs) val_data, val_gt3D = valDataSet.imgStackDepthOnly('test_1') testDataSet = NYUDataset(testSeqs)
if __name__ == '__main__': print "start" generator = Generator() discriminator = Discriminator() print "cuda" discriminator.cuda() generator.cuda() print "opt" criterion = nn.BCELoss() d_optimizer = torch.optim.Adam(discriminator.parameters(), lr=0.0005) g_optimizer = torch.optim.Adam(generator.parameters(), lr=0.0005) #loading data di = NYUImporter('../../DeepPrior/data/NYU') Seq = di.loadSequence('test') trainDataset = NYUDataset([Seq]) X_train, Y_train = trainDataset.imgStackDepthOnly('test') Y_train = np.reshape( Y_train, (Y_train.shape[0], Y_train.shape[1] * Y_train.shape[2])) x_train, x_val, y_train, y_val = train_test_split(X_train, Y_train, test_size=0.2) N = y_train.shape[0] for epoch in range(Nepoch): sum_dis_loss = np.float32(0) sum_gen_loss = np.float32(0) #xp.random.shuffle(train_data) for i in range(0, N, batchsize): input_images = torch.FloatTensor(x_train[i:i + batchsize]) images = Variable(input_images.cuda()) real_poses = Variable(torch.FloatTensor(