-
Notifications
You must be signed in to change notification settings - Fork 534
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update and fix examples to new ModelNet class (#121)
Update classification example to use new ModelNet class in python scripts. Signed-off-by: Jean-Francois Lafleche <jlafleche@nvidia.com>
- Loading branch information
1 parent
48ec4b3
commit 6d22f6c
Showing
3 changed files
with
113 additions
and
60 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 35 additions & 10 deletions
45
examples/Classification/pointcloud_classification_engine.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,42 @@ | ||
import argparse | ||
|
||
import torch | ||
from torch.utils.data import DataLoader | ||
|
||
import kaolin as kal | ||
import kaolin.transforms as tfs | ||
from kaolin import ClassificationEngine | ||
from kaolin.datasets import ModelNet10 | ||
from kaolin.models.PointNet import PointNetClassifier as PointNet | ||
from kaolin.datasets import ModelNet | ||
from kaolin.models.PointNet import PointNetClassifier | ||
from kaolin.transforms import NormalizePointCloud | ||
|
||
norm = NormalizePointCloud() | ||
train_loader = DataLoader(ModelNet10('/path/to/ModelNet10', categories=['chair', 'sofa'], | ||
split='train', rep='pointcloud', transform=norm, device='cuda:0'), | ||
batch_size=12, shuffle=True) | ||
val_loader = DataLoader(ModelNet10('/path/to/ModelNet10', categories=['chair', 'sofa'], | ||
split='test', rep='pointcloud', transform=norm, device='cuda:0'), | ||
batch_size=12) | ||
engine = ClassificationEngine(PointNet(num_classes=2), train_loader, val_loader, device='cuda:0') | ||
|
||
parser = argparse.ArgumentParser() | ||
parser.add_argument('--modelnet-root', type=str, help='Root directory of the ModelNet dataset.') | ||
parser.add_argument('--categories', type=str, nargs='+', default=['chair', 'sofa'], help='list of object classes to use.') | ||
parser.add_argument('--num-points', type=int, default=1024, help='Number of points to sample from meshes.') | ||
parser.add_argument('--epochs', type=int, default=10, help='Number of train epochs.') | ||
parser.add_argument('-lr', '--learning-rate', type=float, default=1e-3, help='Learning rate.') | ||
parser.add_argument('--batch-size', type=int, default=12, help='Batch size.') | ||
parser.add_argument('--device', type=str, default='cuda', help='Device to use.') | ||
|
||
args = parser.parse_args() | ||
|
||
assert len(args.categories) >= 2, 'At least two categories must be specified.' | ||
|
||
transform = tfs.Compose([ | ||
tfs.TriangleMeshToPointCloud(num_samples=args.num_points), | ||
tfs.NormalizePointCloud() | ||
]) | ||
|
||
train_loader = DataLoader(ModelNet(args.modelnet_root, categories=args.categories, | ||
split='train', transform=transform, device=args.device), | ||
batch_size=args.batch_size, shuffle=True) | ||
|
||
val_loader = DataLoader(ModelNet(args.modelnet_root, categories=args.categories, | ||
split='test',transform=transform, device=args.device), | ||
batch_size=args.batch_size) | ||
|
||
model = PointNetClassifier(num_classes=len(args.categories)) | ||
engine = ClassificationEngine(model, train_loader, val_loader, device=args.device) | ||
engine.fit() |