Code Monkey home page Code Monkey logo

Comments (1)

hzxie avatar hzxie commented on June 15, 2024

Just modify the code below.

class ShapeNetDataset(torch.utils.data.dataset.Dataset):
"""ShapeNetDataset class used for PyTorch DataLoader"""
def __init__(self, dataset_type, file_list, n_views_rendering, transforms=None):
self.dataset_type = dataset_type
self.file_list = file_list
self.transforms = transforms
self.n_views_rendering = n_views_rendering
def __len__(self):
return len(self.file_list)
def __getitem__(self, idx):
taxonomy_name, sample_name, rendering_images, volume = self.get_datum(idx)
if self.transforms:
rendering_images = self.transforms(rendering_images)
return taxonomy_name, sample_name, rendering_images, volume
def set_n_views_rendering(self, n_views_rendering):
self.n_views_rendering = n_views_rendering
def get_datum(self, idx):
taxonomy_name = self.file_list[idx]['taxonomy_name']
sample_name = self.file_list[idx]['sample_name']
rendering_image_paths = self.file_list[idx]['rendering_images']
volume_path = self.file_list[idx]['volume']
# Get data of rendering images
if self.dataset_type == DatasetType.TRAIN:
selected_rendering_image_paths = [
rendering_image_paths[i]
for i in random.sample(range(len(rendering_image_paths)), self.n_views_rendering)
]
else:
selected_rendering_image_paths = [rendering_image_paths[i] for i in range(self.n_views_rendering)]
rendering_images = []
for image_path in selected_rendering_image_paths:
rendering_image = cv2.imread(image_path, cv2.IMREAD_UNCHANGED).astype(np.float32) / 255.
if len(rendering_image.shape) < 3:
print('[FATAL] %s It seems that there is something wrong with the image file %s' %
(dt.now(), image_path))
sys.exit(2)
rendering_images.append(rendering_image)
# Get data of volume
_, suffix = os.path.splitext(volume_path)
if suffix == '.mat':
volume = scipy.io.loadmat(volume_path)
volume = volume['Volume'].astype(np.float32)
elif suffix == '.binvox':
with open(volume_path, 'rb') as f:
volume = utils.binvox_rw.read_as_3d_array(f)
volume = volume.data.astype(np.float32)
return taxonomy_name, sample_name, np.asarray(rendering_images), volume

from pix2vox.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.