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)
__status__ = "Development" if __name__ == '__main__': # di = ICVLImporter('../data/ICVL/') # Seq2 = di.loadSequence('test_seq_1') # testSeqs = [Seq2] # # testDataSet = ICVLDataset(testSeqs) # test_data, test_gt3D = testDataSet.imgStackDepthOnly('test_seq_1') di = NYUImporter('../data/NYU/') Seq2 = di.loadSequence('test_1') testSeqs = [Seq2] testDataSet = NYUDataset(testSeqs) test_data, test_gt3D = testDataSet.imgStackDepthOnly('test_1') # load trained network # poseNetParams = PoseRegNetParams(type=11, nChan=1, wIn=128, hIn=128, batchSize=1, numJoints=16, nDims=3) # poseNet = PoseRegNet(numpy.random.RandomState(23455), cfgParams=poseNetParams) # poseNet.load("./ICVL_network_prior.pkl") poseNetParams = PoseRegNetParams(type=11, nChan=1, wIn=128, hIn=128, batchSize=1, numJoints=14, nDims=3) poseNet = PoseRegNet(numpy.random.RandomState(23455), cfgParams=poseNetParams)
floatX = theano.config.floatX # @UndefinedVariable rng = numpy.random.RandomState(23455) print("create data") di = NYUImporter('../data/NYU/') Seq1 = di.loadSequence('train', shuffle=True, rng=rng, docom=True) trainSeqs = [Seq1] Seq2_1 = di.loadSequence('test_1', docom=True) Seq2_2 = di.loadSequence('test_2', docom=True) testSeqs = [Seq2_1, Seq2_2] # create training data trainDataSet = NYUDataset(trainSeqs) train_data, train_gt3D = trainDataSet.imgStackDepthOnly('train') mb = (train_data.nbytes) / (1024 * 1024) print("data size: {}Mb".format(mb)) testDataSet = NYUDataset(testSeqs) test_data1, test_gt3D1 = testDataSet.imgStackDepthOnly('test_1') test_data2, test_gt3D2 = testDataSet.imgStackDepthOnly('test_2') val_data = test_data1 val_gt3D = test_gt3D1 #################################### # resize data dsize = (int(train_data.shape[2] // 2), int(train_data.shape[3] // 2))
print("create data") aug_modes = ['com', 'rot', 'none'] # 'sc', di = NYUImporter('../data/NYU/') Seq1_1 = di.loadSequence('train', shuffle=True, rng=rng, docom=False) Seq1_1 = Seq1_1._replace(name='train_gt') Seq1_2 = di.loadSequence('train', shuffle=True, rng=rng, docom=True) Seq1_2 = Seq1_2._replace(name='train_com') trainSeqs = [Seq1_1, Seq1_2] Seq2_1 = di.loadSequence('test_1', docom=True) Seq2_2 = di.loadSequence('test_2', docom=True) testSeqs = [Seq2_1, Seq2_2] # create training data trainDataSet = NYUDataset(trainSeqs) nSamp = numpy.sum([len(s.data) for s in trainSeqs]) d1, g1 = trainDataSet.imgStackDepthOnly(trainSeqs[0].name) train_data = numpy.ones((nSamp, d1.shape[1], d1.shape[2], d1.shape[3]), dtype='float32') train_gt3D = numpy.ones((nSamp, g1.shape[1], g1.shape[2]), dtype='float32') train_data_cube = numpy.ones((nSamp, 3), dtype='float32') train_data_com = numpy.ones((nSamp, 3), dtype='float32') train_data_M = numpy.ones((nSamp, 3, 3), dtype='float32') del d1, g1 gc.collect() gc.collect() gc.collect() oldIdx = 0 for seq in trainSeqs: d, g = trainDataSet.imgStackDepthOnly(seq.name) train_data[oldIdx:oldIdx+d.shape[0]] = d
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(