classifier, export, torch seed updates

This commit is contained in:
Glenn Jocher committed 2020-10-06 14:54:02 +02:00
1 parent c5d2331897
commit 883924d9dc
3 files changed
+22 -18

No files matched your search

+2 -3
View File
@@ -23,8 +23,7 @@ from scipy.signal import butter, filtfilt
from tqdm import tqdm
from utils.google_utils import gsutil_getsize
from utils.torch_utils import init_seeds as init_torch_seeds
from utils.torch_utils import is_parallel
from utils.torch_utils import is_parallel, init_torch_seeds
# Set printoptions
torch.set_printoptions(linewidth=320, precision=5, profile='long')
@@ -56,7 +55,7 @@ def set_logging(rank=-1):
def init_seeds(seed=0):
random.seed(seed)
np.random.seed(seed)
init_torch_seeds(seed=seed)
init_torch_seeds(seed)
def get_latest_run(search_dir='./runs'):
+9 -11
View File
@@ -8,12 +8,11 @@ import torch
import torch.backends.cudnn as cudnn
import torch.nn as nn
import torch.nn.functional as F
import torchvision.models as models
logger = logging.getLogger(__name__)
def init_seeds(seed=0):
def init_torch_seeds(seed=0):
torch.manual_seed(seed)
# Speed-reproducibility tradeoff https://pytorch.org/docs/stable/notes/randomness.html
@@ -152,16 +151,15 @@ def model_info(model, verbose=False):
def load_classifier(name='resnet101', n=2):
# Loads a pretrained model reshaped to n-class output
model = models.__dict__[name](pretrained=True)
import torchvision
model = torchvision.models.__dict__[name](pretrained=True)
# Display model properties
input_size = [3, 224, 224]
input_space = 'RGB'
input_range = [0, 1]
mean = [0.485, 0.456, 0.406]
std = [0.229, 0.224, 0.225]
for x in ['input_size', 'input_space', 'input_range', 'mean', 'std']:
print(x + ' =', eval(x))
# ResNet model properties
# input_size = [3, 224, 224]
# input_space = 'RGB'
# input_range = [0, 1]
# mean = [0.485, 0.456, 0.406]
# std = [0.229, 0.224, 0.225]
# Reshape output to n classes
filters = model.fc.weight.shape[1]