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

Remove internal metrics in favor of torchmetrics #4287

Merged
merged 16 commits into from
Mar 21, 2022
9 changes: 3 additions & 6 deletions examples/dgcnn_segmentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

import torch
import torch.nn.functional as F
from torchmetrics.functional import jaccard_index

import torch_geometric.transforms as T
from torch_geometric.datasets import ShapeNet
from torch_geometric.loader import DataLoader
from torch_geometric.nn import MLP, DynamicEdgeConv
from torch_geometric.utils import intersection_and_union as i_and_u

category = 'Airplane' # Pass in `None` to train on all categories.
path = osp.join(osp.dirname(osp.realpath(__file__)), '..', 'data', 'ShapeNet')
Expand Down Expand Up @@ -86,11 +86,8 @@ def test(loader):
for data in loader:
data = data.to(device)
pred = model(data).argmax(dim=1)

i, u = i_and_u(pred, data.y, loader.dataset.num_classes, data.batch)
iou = i.cpu().to(torch.float) / u.cpu().to(torch.float)
iou[torch.isnan(iou)] = 1

iou = jaccard_index(pred, data.y,
Borda marked this conversation as resolved.
Show resolved Hide resolved
num_classes=loader.dataset.num_classes)
# Find and filter the relevant classes for each category.
for iou, category in zip(iou.unbind(), data.category.unbind()):
ious[category.item()].append(iou[y_mask[category]])
Expand Down
9 changes: 3 additions & 6 deletions examples/point_transformer_segmentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@
from torch.nn import ReLU
from torch.nn import Sequential as Seq
from torch_cluster import knn_graph
from torchmetrics.functional import jaccard_index

import torch_geometric.transforms as T
from torch_geometric.datasets import ShapeNet
from torch_geometric.loader import DataLoader
from torch_geometric.nn.unpool import knn_interpolate
from torch_geometric.utils import intersection_and_union as i_and_u

category = 'Airplane' # Pass in `None` to train on all categories.
path = osp.join(osp.dirname(osp.realpath(__file__)), '..', 'data', 'ShapeNet')
Expand Down Expand Up @@ -203,11 +203,8 @@ def test(loader):
for data in loader:
data = data.to(device)
pred = model(data.x, data.pos, data.batch).argmax(dim=1)

i, u = i_and_u(pred, data.y, loader.dataset.num_classes, data.batch)
iou = i.cpu().to(torch.float) / u.cpu().to(torch.float)
iou[torch.isnan(iou)] = 1

iou = jaccard_index(pred, data.y,
num_classes=loader.dataset.num_classes)
# Find and filter the relevant classes for each category.
for iou, category in zip(iou.unbind(), data.category.unbind()):
ious[category.item()].append(iou[y_mask[category]])
Expand Down
9 changes: 3 additions & 6 deletions examples/pointnet2_segmentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
import torch
import torch.nn.functional as F
from pointnet2_classification import GlobalSAModule, SAModule
from torchmetrics.functional import jaccard_index

import torch_geometric.transforms as T
from torch_geometric.datasets import ShapeNet
from torch_geometric.loader import DataLoader
from torch_geometric.nn import MLP, knn_interpolate
from torch_geometric.utils import intersection_and_union as i_and_u

category = 'Airplane' # Pass in `None` to train on all categories.
path = osp.join(osp.dirname(osp.realpath(__file__)), '..', 'data', 'ShapeNet')
Expand Down Expand Up @@ -112,11 +112,8 @@ def test(loader):
for data in loader:
data = data.to(device)
pred = model(data).argmax(dim=1)

i, u = i_and_u(pred, data.y, loader.dataset.num_classes, data.batch)
iou = i.cpu().to(torch.float) / u.cpu().to(torch.float)
iou[torch.isnan(iou)] = 1

iou = jaccard_index(pred, data.y,
num_classes=loader.dataset.num_classes)
# Find and filter the relevant classes for each category.
for iou, category in zip(iou.unbind(), data.category.unbind()):
ious[category.item()].append(iou[y_mask[category]])
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
'scikit-image',
'pytorch-memlab',
'class-resolver>=0.3.2',
'torchmetrics>=0.7',
]

test_requires = [
Expand Down
41 changes: 0 additions & 41 deletions test/utils/test_metric.py

This file was deleted.

13 changes: 0 additions & 13 deletions torch_geometric/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,6 @@
structured_negative_sampling,
structured_negative_sampling_feasible)
from .train_test_split_edges import train_test_split_edges
from .metric import (accuracy, true_positive, true_negative, false_positive,
false_negative, precision, recall, f1_score,
intersection_and_union, mean_iou)

__all__ = [
'degree',
Expand Down Expand Up @@ -80,16 +77,6 @@
'structured_negative_sampling',
'structured_negative_sampling_feasible',
'train_test_split_edges',
'accuracy',
'true_positive',
'true_negative',
'false_positive',
'false_negative',
'precision',
'recall',
'f1_score',
'intersection_and_union',
'mean_iou',
]

classes = __all__
201 changes: 0 additions & 201 deletions torch_geometric/utils/metric.py

This file was deleted.