text stringlengths 1 93.6k |
|---|
else:
|
gpus = os.environ["CUDA_VISIBLE_DEVICES"]
|
self.devices = [i for i in range(len(gpus.split(',')))]
|
def inject_default_parser(self):
|
p = self.parser
|
p.add_argument('-d', '--devices', default='',
|
help='set data parallel training')
|
p.add_argument('-c', '--continue', type=extant_file,
|
metavar="FILE",
|
dest="continue_fpath",
|
help='continue from one certain checkpoint')
|
p.add_argument('--local_rank', default=0, type=int,
|
help='process rank on node')
|
def data_parallel(self, model):
|
if self.distributed:
|
model = DistributedDataParallel(model)
|
else:
|
model = torch.nn.DataParallel(model)
|
return model
|
def get_train_loader(self, train_dataset):
|
train_sampler = None
|
is_shuffle = True
|
batch_size = self.args.batch_size
|
if self.distributed:
|
train_sampler = torch.utils.data.distributed.DistributedSampler(
|
train_dataset)
|
batch_size = self.args.batch_size // self.world_size
|
is_shuffle = False
|
train_loader = torch.utils.data.DataLoader(train_dataset,
|
batch_size=batch_size,
|
num_workers=self.args.num_workers,
|
drop_last=False,
|
shuffle=is_shuffle,
|
pin_memory=True,
|
sampler=train_sampler)
|
return train_loader, train_sampler
|
def get_test_loader(self, test_dataset):
|
test_sampler = None
|
is_shuffle = False
|
batch_size = self.args.batch_size
|
if self.distributed:
|
test_sampler = torch.utils.data.distributed.DistributedSampler(
|
test_dataset)
|
batch_size = self.args.batch_size // self.world_size
|
test_loader = torch.utils.data.DataLoader(test_dataset,
|
batch_size=batch_size,
|
num_workers=self.args.num_workers,
|
drop_last=False,
|
shuffle=is_shuffle,
|
pin_memory=True,
|
sampler=test_sampler)
|
return test_loader, test_sampler
|
def all_reduce_tensor(self, tensor, norm=True):
|
if self.distributed:
|
return all_reduce_tensor(tensor, world_size=self.world_size, norm=norm)
|
else:
|
return torch.mean(tensor)
|
def __enter__(self):
|
return self
|
def __exit__(self, type, value, tb):
|
torch.cuda.empty_cache()
|
if type is not None:
|
logger.warning(
|
"A exception occurred during Engine initialization, "
|
"give up running process")
|
return False
|
# <FILESEP>
|
import numpy as np
|
import os
|
import csv
|
import torch
|
import torch.nn as nn
|
import torch.nn.functional as F
|
from GANs.models import GoodGenerator, DC_generator, dc_G
|
from GANs import ResNet32Generator, dcG32
|
from utils import eval_parser
|
from metrics.is_biggan import load_inception_net, torch_calculate_frechet_distance, \
|
torch_cov, numpy_calculate_frechet_distance
|
class evalor():
|
def __init__(self, G, z_dim, model_dir, log_path, device, batchsize=100, dim=1):
|
self.is_flag = False
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.