Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run the model on scans from ScanNet #5

Open
deli4iled opened this issue Jul 20, 2018 · 10 comments
Open

Run the model on scans from ScanNet #5

deli4iled opened this issue Jul 20, 2018 · 10 comments

Comments

@deli4iled
Copy link

Hi, I'd like to run the inference on ScanNet dataset, but I can't figure out how to generate the tfrecords. Could you please share the code to generate them on ScanNet dataset? Thanks

@KyriaAnnwyn
Copy link

@deli4iled Hi/ have you figured out how to generate tfrecord files for ScanComplete running? I've tried to train this Net using different dataset, but Have some error in my tfrecord files:
image

@KyriaAnnwyn
Copy link

@deli4iled @angeladai
I've tried to set batch-size to 1 to check that shapes are ok, but I still get the error, though I've checked that all the data I'm writing to tfrecorf has 16384 sizes.
Can't find where this multiplication by 8 comes from, when I use batch_size = 1

@KyriaAnnwyn
Copy link

I've found the error in my code for tfrecords generation it was in using np array of ints to fill bytes feature in the record. ^)

@livc
Copy link

livc commented Apr 15, 2019

@KyriaAnnwyn Hi, I'm working on this net with my own data, but I can't find the way to transfer my own data to the tfrecords, could you please share the code? Thanks.

@KyriaAnnwyn
Copy link

@livc Here is my code for tfrecords creation:
`
import numpy as np
import tensorflow as tf
import os
import argparse
import sys
import random

_RESOLUTIONS = ['5cm', '9cm', '19cm']
_INPUT_FEATURE = 'input_sdf'
_TARGET_FEATURE = 'target_df'
_TARGET_SEM_FEATURE = 'target_sem'
_HEIGHT_JITTER = [5, 3, 0]
hierarchy_level = 3

def float_feature(value):
"""Wrapper for inserting float features into Example proto."""
if not isinstance(value, (tuple, list)):
#value = [value]
print(value.shape)
return tf.train.Feature(float_list=tf.train.FloatList(value=value))

def int64_feature(value):
"""Wrapper for inserting int64 features into Example proto."""
if not isinstance(value, (tuple, list)):
value = [value]
return tf.train.Feature(int64_list=tf.train.Int64List(value=value))

def bytes_feature(value):
"""Wrapper for inserting bytes features into Example proto."""
if not isinstance(value, (tuple, list)):
value = [value]
return tf.train.Feature(bytes_list=tf.train.BytesList(value=value))

def createTFRecord(args, pair, number):

key_input = RESOLUTIONS[hierarchy_level - 1] + '' + _INPUT_FEATURE
key_target = RESOLUTIONS[hierarchy_level - 1] + '' + _TARGET_FEATURE
key_target_sem = RESOLUTIONS[hierarchy_level - 1] + '' + _TARGET_SEM_FEATURE

#read full and hole tsdfs ans save then to example
insample = np.load(args.infolder + '/' + pair[0])
target = np.load(args.infolder + '/' + pair[1])
print(args.infolder + '/' + pair[0], args.infolder + '/' + pair[1])

center = [insample.shape[0]/2, insample.shape[1]/2, insample.shape[2]/2]
print(center)

#cut areas with specific size fron the input tsdfs, consider that the model shoul be somewhere in the center
target2write = []
insample2write = []
tfrecords_filename = args.outfolder + '/' + 'smpl_scancomplete_train_' + str(number) + '.tfrecords'
writer = tf.python_io.TFRecordWriter(tfrecords_filename)

for numsample in xrange(10*args.batch_size):
move = [random.randint(-(center[0] - args.dim_block / 2),center[0] - args.dim_block / 2),
random.randint(-(center[1] - args.height_block / 2), center[1] - args.height_block / 2),
random.randint(-(center[2] - args.dim_block / 2), center[2] - args.dim_block / 2)]

newCenter = center + move
insample_small = insample[(newCenter[0] - args.dim_block / 2):(newCenter[0] + args.dim_block / 2),
  (newCenter[1] - args.height_block / 2):(newCenter[1] + args.height_block / 2),
  (newCenter[2] - args.dim_block / 2):(newCenter[2] + args.dim_block / 2)]
target_small = target[(newCenter[0] - args.dim_block / 2):(newCenter[0] + args.dim_block / 2),
  (newCenter[1] - args.height_block / 2):(newCenter[1] + args.height_block / 2),
  (newCenter[2] - args.dim_block / 2):(newCenter[2] + args.dim_block / 2)]
#sem_dummy = np.ones(args.dim_block*args.dim_block*args.height_block, dtype = int)
#target2write.append(insample_small.ravel())
#insample2write.append(target_small.ravel())
#print(insample_small.shape)
#print(insample_small.ravel().shape)


#insample2write = np.array(insample2write).ravel()
#target2write = np.array(target2write).ravel()
#print(insample2write.shape)

insample_small = np.array(insample_small.ravel())
target_small = np.array(target_small.ravel())
semantics = np.ones(insample_small.size, dtype = np.int8)

print('Sizes:')
print(insample_small.size, target_small.size, semantics.size)

print('Build example')
example = tf.train.Example(features=tf.train.Features(feature={
      key_target: float_feature(target_small),
      key_target_sem: bytes_feature(semantics.tostring()),
      #key_target_sem: bytes_feature(semantics),
      key_input: float_feature(insample_small)
        }))
writer.write(example.SerializeToString())

writer.close()

def convertList(args):
substr = "_holes"
tsdfNames = [f for f in os.listdir(args.infolder) if substr in f]
name_pairs = []
number = 0

for name in tsdfNames:
targetN = name.replace(substr,'')
#targetN.replace(substr,'')
pair = (name, targetN)
name_pairs.append(pair)

for pair in name_pairs:
createTFRecord(args, pair, number)
number = number + 1

def parse_arguements(argv):
parser = argparse.ArgumentParser()

parser.add_argument('--infolder', type=str, help='Folder with input *.npy tsdfs',
default='../../TSDFBodyModelsBHNPY')
parser.add_argument('--outfolder', type=str, help='Folder with output tfrecords',
default='../../TSDFBodyModelsBHTFRecord')
#parser.add_argument('--pattern', type = str, help='File pattern for *.npy tsdfs', default='')
parser.add_argument('--batch_size', type=int, help='Number of blocks in each batch.', default=8)
parser.add_argument('--dim_block', type=int, help='Input/target block x/z dim.', default=32)
parser.add_argument('--height_block', type=int, help='Input/target block y dim.', default=16)

return parser.parse_args(argv)

if name == 'main':
convertList(parse_arguements(sys.argv[1:]))
`

@livc
Copy link

livc commented Apr 16, 2019

@KyriaAnnwyn Thank you!

@euzer
Copy link

euzer commented Apr 23, 2019

thank you @KyriaAnnwyn for sharing this code. I got a question about how can i get numpy array of tsdfs ?
thanks !

@qiji77
Copy link

qiji77 commented Oct 29, 2019

hello,
I have the same problem too,
Could you please tell me how to use my own dataset?(obj or images?)

@santhu937
Copy link

@qiji77
hi, did u get the solution to generate tfrecords from obj file?
I need to test on my own data.

@santhu937
Copy link

@KyriaAnnwyn can u please share the code file to convert obj file to tfrecords because I'm getting lot of errors with the above code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants