Skip to content

Instantly share code, notes, and snippets.

@n2cholas
n2cholas / benchmark.py
Created September 6, 2020 19:15
Benchmarking ignite master branch vs metrics_impl on metrics.
'''
To run the CPU benchmark: `CUDA_VISIBLE_DEVICES="" python benchmark.py --name cpu`
To run the GPU benchmark: `CUDA_VISIBLE_DEVICES=0 python benchmark.py --name cuda`
To run the distributed benchmark: `python -u -m torch.distributed.launch --nproc_per_node=2 --use_env benchmark.py --name dist`
'''
import argparse
import time
import math
import math
import torch
def tfm2theta_2d(tfm, h, w):
"""Returns theta for affine_grid"""
theta = tfm.new_zeros((tfm.size(0), 2, 3))
theta[:,0,0] = tfm[:,0,0]
theta[:,0,1] = tfm[:,0,1]*h/w
theta[:,0,2] = tfm[:,0,2]*2/w + tfm[:,0,0] + tfm[:,0,1] - 1
import sys
import time
import torch
from torch import nn
import torchvision
from torchvision import transforms
from ignite.metrics import Accuracy
import sys
import time
import torch
from torch import nn
import torchvision
from torchvision import transforms
from ignite.metrics import Accuracy