Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
516 views
in Technique[技术] by (71.8m points)

python - How to load Pix3D voxel data from .mat files in Tensorflow 2 as labels

I am working on a 3D voxel model reconstruction network and I am struggling with loading .mat voxel models (from Pix3D dataset) as labels in TF2. I had two ideas:

  1. Using tf.data.Dataset.from_tensor_slices(img_paths, voxel_mat_paths) and then train_ds.map(self.process_path) with scipy.io.loadmat function. However loadmat can't handle string tensor from TF.
def process_path(self, img_path, voxel):
   label = self.get_label(label_path)
   img = tf.io.read_file(img_path)
   img = self.decode_img(img)
   return img, voxel

def get_label(self, voxel_path):
   mat = scipy.io.loadmat(voxel_path)
   return mat['voxel']
  1. The second idea was to load all .mat files into a list and then pass it to from_tensor_slices
train_img_paths = [cfg.PIX3D_PATH + example['img'] for example in self.dataset_desc_train]
train_voxel_paths = [cfg.PIX3D_PATH + example['voxel'] for example in self.dataset_desc_train]
train_voxel = [scipy.io.loadmat(path)['voxel'] for path in train_voxel_paths]
train_ds = tf.data.Dataset.from_tensor_slices((train_img_paths, train_voxel))
train_ds = train_ds.map(self.process_path, num_parallel_calls=1)

Then it should be possible to decode image in process_path and pass through voxel data. However, tf.data.Dataset.from_tensor_slices((train_img_paths, train_voxel)) never finishes.

Basically, I want to load images (which works fine) and voxels as labels for these images, however, I am not sure how should I implement this.

question from:https://stackoverflow.com/questions/65864778/how-to-load-pix3d-voxel-data-from-mat-files-in-tensorflow-2-as-labels

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...