Compare commits
15 commits
master
...
torchhub_l
Author | SHA1 | Date | |
---|---|---|---|
b7596093f0 | |||
dfe30b6baf | |||
3e961c3a14 | |||
ffe84ae70a | |||
9189f07093 | |||
46758dadf8 | |||
db408837c2 | |||
8e3ef240b8 | |||
e0b6d222b4 | |||
4c12145030 | |||
5639257b22 | |||
0cabbfb67c | |||
b1d9921414 | |||
9e28f35158 | |||
21d7520e14 |
|
@ -530,8 +530,8 @@ class Decoder(nn.Module):
|
|||
|
||||
self.initialize_decoder_states(memory, mask=None)
|
||||
|
||||
mel_lengths = torch.zeros([memory.size(0)], dtype=torch.int32).cuda()
|
||||
not_finished = torch.ones([memory.size(0)], dtype=torch.int32).cuda()
|
||||
mel_lengths = torch.zeros([memory.size(0)], dtype=torch.int32).to(memory.device)
|
||||
not_finished = torch.ones([memory.size(0)], dtype=torch.int32).to(memory.device)
|
||||
mel_outputs, gate_outputs, alignments = [], [], []
|
||||
while True:
|
||||
decoder_input = self.prenet(decoder_input)
|
||||
|
|
58
hubconf.py
58
hubconf.py
|
@ -3,6 +3,7 @@ import torch
|
|||
import os
|
||||
import sys
|
||||
|
||||
|
||||
# from https://github.com/NVIDIA/DeepLearningExamples/blob/master/PyTorch/SpeechSynthesis/Tacotron2/inference.py
|
||||
def checkpoint_from_distributed(state_dict):
|
||||
"""
|
||||
|
@ -35,6 +36,17 @@ def unwrap_distributed(state_dict):
|
|||
return new_state_dict
|
||||
|
||||
|
||||
def _download_checkpoint(checkpoint, force_reload):
|
||||
model_dir = os.path.join(torch.hub._get_torch_home(), 'checkpoints')
|
||||
if not os.path.exists(model_dir):
|
||||
os.makedirs(model_dir)
|
||||
ckpt_file = os.path.join(model_dir, os.path.basename(checkpoint))
|
||||
if not os.path.exists(ckpt_file) or force_reload:
|
||||
sys.stderr.write('Downloading checkpoint from {}\n'.format(checkpoint))
|
||||
urllib.request.urlretrieve(checkpoint, ckpt_file)
|
||||
return ckpt_file
|
||||
|
||||
|
||||
dependencies = ['torch']
|
||||
|
||||
|
||||
|
@ -66,10 +78,7 @@ def nvidia_ncf(pretrained=True, **kwargs):
|
|||
checkpoint = 'https://developer.nvidia.com/joc-ncf-fp16-pyt-20190225'
|
||||
else:
|
||||
checkpoint = 'https://developer.nvidia.com/joc-ncf-fp32-pyt-20190225'
|
||||
ckpt_file = os.path.basename(checkpoint)
|
||||
if not os.path.exists(ckpt_file) or force_reload:
|
||||
sys.stderr.write('Downloading checkpoint from {}\n'.format(checkpoint))
|
||||
urllib.request.urlretrieve(checkpoint, ckpt_file)
|
||||
ckpt_file = _download_checkpoint(checkpoint, force_reload)
|
||||
ckpt = torch.load(ckpt_file)
|
||||
|
||||
if checkpoint_from_distributed(ckpt):
|
||||
|
@ -127,13 +136,10 @@ def nvidia_tacotron2(pretrained=True, **kwargs):
|
|||
|
||||
if pretrained:
|
||||
if fp16:
|
||||
checkpoint = 'https://developer.nvidia.com/joc-tacotron2-fp16-pyt-20190306'
|
||||
checkpoint = 'https://api.ngc.nvidia.com/v2/models/nvidia/tacotron2_pyt_ckpt_amp/versions/19.09.0/files/nvidia_tacotron2pyt_fp16_20190427'
|
||||
else:
|
||||
checkpoint = 'https://developer.nvidia.com/joc-tacotron2-fp32-pyt-20190306'
|
||||
ckpt_file = os.path.basename(checkpoint)
|
||||
if not os.path.exists(ckpt_file) or force_reload:
|
||||
sys.stderr.write('Downloading checkpoint from {}\n'.format(checkpoint))
|
||||
urllib.request.urlretrieve(checkpoint, ckpt_file)
|
||||
checkpoint = 'https://api.ngc.nvidia.com/v2/models/nvidia/tacotron2_pyt_ckpt_fp32/versions/19.09.0/files/nvidia_tacotron2pyt_fp32_20190427'
|
||||
ckpt_file = _download_checkpoint(checkpoint, force_reload)
|
||||
ckpt = torch.load(ckpt_file)
|
||||
state_dict = ckpt['state_dict']
|
||||
if checkpoint_from_distributed(state_dict):
|
||||
|
@ -187,13 +193,10 @@ def nvidia_waveglow(pretrained=True, **kwargs):
|
|||
|
||||
if pretrained:
|
||||
if fp16:
|
||||
checkpoint = 'https://developer.nvidia.com/joc-waveglow-fp16-pyt-20190306'
|
||||
checkpoint = 'https://api.ngc.nvidia.com/v2/models/nvidia/waveglow_ckpt_amp/versions/19.09.0/files/nvidia_waveglowpyt_fp16_20190427'
|
||||
else:
|
||||
checkpoint = 'https://developer.nvidia.com/joc-waveglow-fp32-pyt-20190306'
|
||||
ckpt_file = os.path.basename(checkpoint)
|
||||
if not os.path.exists(ckpt_file) or force_reload:
|
||||
sys.stderr.write('Downloading checkpoint from {}\n'.format(checkpoint))
|
||||
urllib.request.urlretrieve(checkpoint, ckpt_file)
|
||||
checkpoint = 'https://api.ngc.nvidia.com/v2/models/nvidia/waveglow_ckpt_fp32/versions/19.09.0/files/nvidia_waveglowpyt_fp32_20190427'
|
||||
ckpt_file = _download_checkpoint(checkpoint, force_reload)
|
||||
ckpt = torch.load(ckpt_file)
|
||||
state_dict = ckpt['state_dict']
|
||||
if checkpoint_from_distributed(state_dict):
|
||||
|
@ -225,13 +228,15 @@ def nvidia_waveglow(pretrained=True, **kwargs):
|
|||
def nvidia_ssd_processing_utils():
|
||||
import numpy as np
|
||||
import skimage
|
||||
from skimage import io, transform
|
||||
|
||||
from PyTorch.Detection.SSD.src.utils import dboxes300_coco, Encoder
|
||||
|
||||
class Processing:
|
||||
@staticmethod
|
||||
def load_image(image_path):
|
||||
"""Code from Loading_Pretrained_Models.ipynb - a Caffe2 tutorial"""
|
||||
img = skimage.img_as_float(skimage.io.imread(image_path))
|
||||
img = skimage.img_as_float(io.imread(image_path))
|
||||
if len(img.shape) == 2:
|
||||
img = np.array([img, img, img]).swapaxes(0, 2)
|
||||
return img
|
||||
|
@ -243,13 +248,13 @@ def nvidia_ssd_processing_utils():
|
|||
if (aspect > 1):
|
||||
# landscape orientation - wide image
|
||||
res = int(aspect * input_height)
|
||||
imgScaled = skimage.transform.resize(img, (input_width, res))
|
||||
imgScaled = transform.resize(img, (input_width, res))
|
||||
if (aspect < 1):
|
||||
# portrait orientation - tall image
|
||||
res = int(input_width / aspect)
|
||||
imgScaled = skimage.transform.resize(img, (res, input_height))
|
||||
imgScaled = transform.resize(img, (res, input_height))
|
||||
if (aspect == 1):
|
||||
imgScaled = skimage.transform.resize(img, (input_width, input_height))
|
||||
imgScaled = transform.resize(img, (input_width, input_height))
|
||||
return imgScaled
|
||||
|
||||
@staticmethod
|
||||
|
@ -270,6 +275,7 @@ def nvidia_ssd_processing_utils():
|
|||
NHWC = np.array(inputs)
|
||||
NCHW = np.swapaxes(np.swapaxes(NHWC, 1, 3), 2, 3)
|
||||
tensor = torch.from_numpy(NCHW)
|
||||
tensor = tensor.contiguous()
|
||||
tensor = tensor.cuda()
|
||||
tensor = tensor.float()
|
||||
if fp16:
|
||||
|
@ -326,6 +332,7 @@ def nvidia_ssd_processing_utils():
|
|||
|
||||
return Processing()
|
||||
|
||||
|
||||
def nvidia_ssd(pretrained=True, **kwargs):
|
||||
"""Constructs an SSD300 model.
|
||||
For detailed information on model input and output, training recipies, inference and performance
|
||||
|
@ -356,14 +363,9 @@ def nvidia_ssd(pretrained=True, **kwargs):
|
|||
m = batchnorm_to_float(m)
|
||||
|
||||
if pretrained:
|
||||
if fp16:
|
||||
checkpoint = 'https://developer.nvidia.com/joc-ssd-fp16-pyt-20190225'
|
||||
else:
|
||||
checkpoint = 'https://developer.nvidia.com/joc-ssd-fp32-pyt-20190225'
|
||||
ckpt_file = os.path.basename(checkpoint)
|
||||
if not os.path.exists(ckpt_file) or force_reload:
|
||||
sys.stderr.write('Downloading checkpoint from {}\n'.format(checkpoint))
|
||||
urllib.request.urlretrieve(checkpoint, ckpt_file)
|
||||
checkpoint = 'https://api.ngc.nvidia.com/v2/models/nvidia/ssd_pyt_ckpt_amp/versions/19.09.0/files/nvidia_ssdpyt_fp16_190826.pt'
|
||||
# ckpt = torch.hub.load_state_dict_from_url(checkpoint, progress=True, check_hash=False)
|
||||
ckpt_file = _download_checkpoint(checkpoint, force_reload)
|
||||
ckpt = torch.load(ckpt_file)
|
||||
ckpt = ckpt['model']
|
||||
if checkpoint_from_distributed(ckpt):
|
||||
|
|
Loading…
Reference in a new issue