From fadc74ad44f504101089fff1f3a78909fc499522 Mon Sep 17 00:00:00 2001 From: "xiaoke@ivgsz_171" Date: Thu, 22 Sep 2022 10:37:52 +0800 Subject: [PATCH] py3.x and pt1.8.x with dockerfile --- .dockerignore | 1 + code/convolutional_rnn/__init__.py | 5 + code/convolutional_rnn/functional.py | 38 +- code/convolutional_rnn/module.py | 524 +++++++++++++++++---------- code/demo.py | 7 +- code/models.py | 8 +- dockerfile | 15 + 7 files changed, 373 insertions(+), 225 deletions(-) create mode 100644 .dockerignore create mode 100644 dockerfile diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..fa29cdf --- /dev/null +++ b/.dockerignore @@ -0,0 +1 @@ +** \ No newline at end of file diff --git a/code/convolutional_rnn/__init__.py b/code/convolutional_rnn/__init__.py index d095f0f..50c94a8 100644 --- a/code/convolutional_rnn/__init__.py +++ b/code/convolutional_rnn/__init__.py @@ -1,3 +1,8 @@ +from .module import Conv1dRNN +from .module import Conv1dLSTM +from .module import Conv1dPeepholeLSTM +from .module import Conv1dGRU + from .module import Conv2dRNN from .module import Conv2dLSTM from .module import Conv2dPeepholeLSTM diff --git a/code/convolutional_rnn/functional.py b/code/convolutional_rnn/functional.py index 52fd30a..7f91903 100644 --- a/code/convolutional_rnn/functional.py +++ b/code/convolutional_rnn/functional.py @@ -2,7 +2,11 @@ import torch import torch.nn.functional as F -from torch.nn._functions.thnn import rnnFusedPointwise as fusedBackend +try: + # pytorch<=0.4.1 + from torch.nn._functions.thnn import rnnFusedPointwise as fusedBackend +except ImportError: + fusedBackend = None from .utils import _single, _pair, _triple @@ -19,7 +23,7 @@ def RNNTanhCell(input, hidden, w_ih, w_hh, b_ih=None, b_hh=None, linear_func=Non """ Copied from torch.nn._functions.rnn and modified """ if linear_func is None: linear_func = F.linear - hy = F.tanh(linear_func(input, w_ih, b_ih) + linear_func(hidden, w_hh, b_hh)) + hy = torch.tanh(linear_func(input, w_ih, b_ih) + linear_func(hidden, w_hh, b_hh)) return hy @@ -27,7 +31,7 @@ def LSTMCell(input, hidden, w_ih, w_hh, b_ih=None, b_hh=None, linear_func=None): """ Copied from torch.nn._functions.rnn and modified """ if linear_func is None: linear_func = F.linear - if input.is_cuda and linear_func is F.linear: + if input.is_cuda and linear_func is F.linear and fusedBackend is not None: igates = linear_func(input, w_ih) hgates = linear_func(hidden[0], w_hh) state = fusedBackend.LSTMFused.apply @@ -37,13 +41,13 @@ def LSTMCell(input, hidden, w_ih, w_hh, b_ih=None, b_hh=None, linear_func=None): gates = linear_func(input, w_ih, b_ih) + linear_func(hx, w_hh, b_hh) ingate, forgetgate, cellgate, outgate = gates.chunk(4, 1) - ingate = F.sigmoid(ingate) - forgetgate = F.sigmoid(forgetgate) - cellgate = F.tanh(cellgate) - outgate = F.sigmoid(outgate) + ingate = torch.sigmoid(ingate) + forgetgate = torch.sigmoid(forgetgate) + cellgate = torch.tanh(cellgate) + outgate = torch.sigmoid(outgate) cy = (forgetgate * cx) + (ingate * cellgate) - hy = outgate * F.tanh(cy) + hy = outgate * torch.tanh(cy) return hy, cy @@ -58,15 +62,15 @@ def PeepholeLSTMCell(input, hidden, w_ih, w_hh, w_pi, w_pf, w_po, ingate += linear_func(cx, w_pi) forgetgate += linear_func(cx, w_pf) - ingate = F.sigmoid(ingate) - forgetgate = F.sigmoid(forgetgate) - cellgate = F.tanh(cellgate) + ingate = torch.sigmoid(ingate) + forgetgate = torch.sigmoid(forgetgate) + cellgate = torch.tanh(cellgate) cy = (forgetgate * cx) + (ingate * cellgate) outgate += linear_func(cy, w_po) - outgate = F.sigmoid(outgate) + outgate = torch.sigmoid(outgate) - hy = outgate * F.tanh(cy) + hy = outgate * torch.tanh(cy) return hy, cy @@ -75,7 +79,7 @@ def GRUCell(input, hidden, w_ih, w_hh, b_ih=None, b_hh=None, linear_func=None): """ Copied from torch.nn._functions.rnn and modified """ if linear_func is None: linear_func = F.linear - if input.is_cuda and linear_func is F.linear: + if input.is_cuda and linear_func is F.linear and fusedBackend is not None: gi = linear_func(input, w_ih) gh = linear_func(hidden, w_hh) state = fusedBackend.GRUFused.apply @@ -85,9 +89,9 @@ def GRUCell(input, hidden, w_ih, w_hh, b_ih=None, b_hh=None, linear_func=None): i_r, i_i, i_n = gi.chunk(3, 1) h_r, h_i, h_n = gh.chunk(3, 1) - resetgate = F.sigmoid(i_r + h_r) - inputgate = F.sigmoid(i_i + h_i) - newgate = F.tanh(i_n + resetgate * h_n) + resetgate = torch.sigmoid(i_r + h_r) + inputgate = torch.sigmoid(i_i + h_i) + newgate = torch.tanh(i_n + resetgate * h_n) hy = newgate + inputgate * (hidden - newgate) return hy diff --git a/code/convolutional_rnn/module.py b/code/convolutional_rnn/module.py index 9313ff7..f24ff69 100644 --- a/code/convolutional_rnn/module.py +++ b/code/convolutional_rnn/module.py @@ -11,20 +11,20 @@ class ConvNdRNNBase(torch.nn.Module): def __init__(self, - mode, - in_channels, - out_channels, - kernel_size, - num_layers=1, - bias=True, - batch_first=False, - dropout=0., - bidirectional=False, - convndim=2, - stride=1, - dilation=1, - groups=1): - super(ConvNdRNNBase, self).__init__() + mode: str, + in_channels: int, + out_channels: int, + kernel_size: Union[int, Sequence[int]], + num_layers: int=1, + bias: bool=True, + batch_first: bool=False, + dropout: float=0., + bidirectional: bool=False, + convndim: int=2, + stride: Union[int, Sequence[int]]=1, + dilation: Union[int, Sequence[int]]=1, + groups: int=1): + super().__init__() self.mode = mode self.in_channels = in_channels self.out_channels = out_channels @@ -216,21 +216,143 @@ def all_weights(self): return [[getattr(self, weight) for weight in weights] for weights in self._all_weights] +class Conv1dRNN(ConvNdRNNBase): + def __init__(self, + in_channels: int, + out_channels: int, + kernel_size: Union[int, Sequence[int]], + nonlinearity: str='tanh', + num_layers: int=1, + bias: bool=True, + batch_first: bool=False, + dropout: float=0., + bidirectional: bool=False, + stride: Union[int, Sequence[int]]=1, + dilation: Union[int, Sequence[int]]=1, + groups: int=1): + if nonlinearity == 'tanh': + mode = 'RNN_TANH' + elif nonlinearity == 'relu': + mode = 'RNN_RELU' + else: + raise ValueError("Unknown nonlinearity '{}'".format(nonlinearity)) + super().__init__( + mode=mode, + in_channels=in_channels, + out_channels=out_channels, + kernel_size=kernel_size, + num_layers=num_layers, + bias=bias, + batch_first=batch_first, + dropout=dropout, + bidirectional=bidirectional, + convndim=1, + stride=stride, + dilation=dilation, + groups=groups) + + +class Conv1dPeepholeLSTM(ConvNdRNNBase): + def __init__(self, + in_channels: int, + out_channels: int, + kernel_size: Union[int, Sequence[int]], + num_layers: int=1, + bias: bool=True, + batch_first: bool=False, + dropout: float=0., + bidirectional: bool=False, + stride: Union[int, Sequence[int]]=1, + dilation: Union[int, Sequence[int]]=1, + groups: int=1): + super().__init__( + mode='PeepholeLSTM', + in_channels=in_channels, + out_channels=out_channels, + kernel_size=kernel_size, + num_layers=num_layers, + bias=bias, + batch_first=batch_first, + dropout=dropout, + bidirectional=bidirectional, + convndim=1, + stride=stride, + dilation=dilation, + groups=groups) + + +class Conv1dLSTM(ConvNdRNNBase): + def __init__(self, + in_channels: int, + out_channels: int, + kernel_size: Union[int, Sequence[int]], + num_layers: int=1, + bias: bool=True, + batch_first: bool=False, + dropout: float=0., + bidirectional: bool=False, + stride: Union[int, Sequence[int]]=1, + dilation: Union[int, Sequence[int]]=1, + groups: int=1): + super().__init__( + mode='LSTM', + in_channels=in_channels, + out_channels=out_channels, + kernel_size=kernel_size, + num_layers=num_layers, + bias=bias, + batch_first=batch_first, + dropout=dropout, + bidirectional=bidirectional, + convndim=1, + stride=stride, + dilation=dilation, + groups=groups) + + +class Conv1dGRU(ConvNdRNNBase): + def __init__(self, + in_channels: int, + out_channels: int, + kernel_size: Union[int, Sequence[int]], + num_layers: int=1, + bias: bool=True, + batch_first: bool=False, + dropout: float=0., + bidirectional: bool=False, + stride: Union[int, Sequence[int]]=1, + dilation: Union[int, Sequence[int]]=1, + groups: int=1): + super().__init__( + mode='GRU', + in_channels=in_channels, + out_channels=out_channels, + kernel_size=kernel_size, + num_layers=num_layers, + bias=bias, + batch_first=batch_first, + dropout=dropout, + bidirectional=bidirectional, + convndim=1, + stride=stride, + dilation=dilation, + groups=groups) + class Conv2dRNN(ConvNdRNNBase): def __init__(self, - in_channels, - out_channels, - kernel_size, - nonlinearity='tanh', - num_layers=1, - bias=True, - batch_first=False, - dropout=0., - bidirectional=False, - stride=1, - dilation=1, - groups=1): + in_channels: int, + out_channels: int, + kernel_size: Union[int, Sequence[int]], + nonlinearity: str='tanh', + num_layers: int=1, + bias: bool=True, + batch_first: bool=False, + dropout: float=0., + bidirectional: bool=False, + stride: Union[int, Sequence[int]]=1, + dilation: Union[int, Sequence[int]]=1, + groups: int=1): if nonlinearity == 'tanh': mode = 'RNN_TANH' elif nonlinearity == 'relu': @@ -255,17 +377,17 @@ def __init__(self, class Conv2dLSTM(ConvNdRNNBase): def __init__(self, - in_channels, - out_channels, - kernel_size, - num_layers=1, - bias=True, - batch_first=False, - dropout=0., - bidirectional=False, - stride=1, - dilation=1, - groups=1): + in_channels: int, + out_channels: int, + kernel_size: Union[int, Sequence[int]], + num_layers: int=1, + bias: bool=True, + batch_first: bool=False, + dropout: float=0., + bidirectional: bool=False, + stride: Union[int, Sequence[int]]=1, + dilation: Union[int, Sequence[int]]=1, + groups: int=1): super().__init__( mode='LSTM', in_channels=in_channels, @@ -284,17 +406,17 @@ def __init__(self, class Conv2dPeepholeLSTM(ConvNdRNNBase): def __init__(self, - in_channels, - out_channels, - kernel_size, - num_layers=1, - bias=True, - batch_first=False, - dropout=0., - bidirectional=False, - stride=1, - dilation=1, - groups=1): + in_channels: int, + out_channels: int, + kernel_size: Union[int, Sequence[int]], + num_layers: int=1, + bias: bool=True, + batch_first: bool=False, + dropout: float=0., + bidirectional: bool=False, + stride: Union[int, Sequence[int]]=1, + dilation: Union[int, Sequence[int]]=1, + groups: int=1): super().__init__( mode='PeepholeLSTM', in_channels=in_channels, @@ -313,18 +435,18 @@ def __init__(self, class Conv2dGRU(ConvNdRNNBase): def __init__(self, - in_channels, - out_channels, - kernel_size, - num_layers=1, - bias=True, - batch_first=False, - dropout=0., - bidirectional=False, - stride=1, - dilation=1, - groups=1): - super(Conv2dGRU, self).__init__( + in_channels: int, + out_channels: int, + kernel_size: Union[int, Sequence[int]], + num_layers: int=1, + bias: bool=True, + batch_first: bool=False, + dropout: float=0., + bidirectional: bool=False, + stride: Union[int, Sequence[int]]=1, + dilation: Union[int, Sequence[int]]=1, + groups: int=1): + super().__init__( mode='GRU', in_channels=in_channels, out_channels=out_channels, @@ -342,18 +464,18 @@ def __init__(self, class Conv3dRNN(ConvNdRNNBase): def __init__(self, - in_channels, - out_channels, - kernel_size, - nonlinearity='tanh', - num_layers=1, - bias=True, - batch_first=False, - dropout=0., - bidirectional=False, - stride=1, - dilation=1, - groups=1): + in_channels: int, + out_channels: int, + kernel_size: Union[int, Sequence[int]], + nonlinearity: str='tanh', + num_layers: int=1, + bias: bool=True, + batch_first: bool=False, + dropout: float=0., + bidirectional: bool=False, + stride: Union[int, Sequence[int]]=1, + dilation: Union[int, Sequence[int]]=1, + groups: int=1): if nonlinearity == 'tanh': mode = 'RNN_TANH' elif nonlinearity == 'relu': @@ -378,17 +500,17 @@ def __init__(self, class Conv3dLSTM(ConvNdRNNBase): def __init__(self, - in_channels, - out_channels, - kernel_size, - num_layers=1, - bias=True, - batch_first=False, - dropout=0., - bidirectional=False, - stride=1, - dilation=1, - groups=1): + in_channels: int, + out_channels: int, + kernel_size: Union[int, Sequence[int]], + num_layers: int=1, + bias: bool=True, + batch_first: bool=False, + dropout: float=0., + bidirectional: bool=False, + stride: Union[int, Sequence[int]]=1, + dilation: Union[int, Sequence[int]]=1, + groups: int=1): super().__init__( mode='LSTM', in_channels=in_channels, @@ -407,17 +529,17 @@ def __init__(self, class Conv3dPeepholeLSTM(ConvNdRNNBase): def __init__(self, - in_channels, - out_channels, - kernel_size, - num_layers=1, - bias=True, - batch_first=False, - dropout=0., - bidirectional=False, - stride=1, - dilation=1, - groups=1): + in_channels: int, + out_channels: int, + kernel_size: Union[int, Sequence[int]], + num_layers: int=1, + bias: bool=True, + batch_first: bool=False, + dropout: float=0., + bidirectional: bool=False, + stride: Union[int, Sequence[int]]=1, + dilation: Union[int, Sequence[int]]=1, + groups: int=1): super().__init__( mode='PeepholeLSTM', in_channels=in_channels, @@ -436,17 +558,17 @@ def __init__(self, class Conv3dGRU(ConvNdRNNBase): def __init__(self, - in_channels, - out_channels, - kernel_size, - num_layers=1, - bias=True, - batch_first=False, - dropout=0., - bidirectional=False, - stride=1, - dilation=1, - groups=1): + in_channels: int, + out_channels: int, + kernel_size: Union[int, Sequence[int]], + num_layers: int=1, + bias: bool=True, + batch_first: bool=False, + dropout: float=0., + bidirectional: bool=False, + stride: Union[int, Sequence[int]]=1, + dilation: Union[int, Sequence[int]]=1, + groups: int=1): super().__init__( mode='GRU', in_channels=in_channels, @@ -465,15 +587,15 @@ def __init__(self, class ConvRNNCellBase(torch.nn.Module): def __init__(self, - mode, - in_channels, - out_channels, - kernel_size, - bias=True, - convndim=2, - stride=1, - dilation=1, - groups=1 + mode: str, + in_channels: int, + out_channels: int, + kernel_size: Union[int, Sequence[int]], + bias: bool=True, + convndim: int=2, + stride: Union[int, Sequence[int]]=1, + dilation: Union[int, Sequence[int]]=1, + groups: int=1 ): super().__init__() self.mode = mode @@ -593,14 +715,14 @@ def forward(self, input, hx=None): class Conv1dRNNCell(ConvRNNCellBase): def __init__(self, - in_channels, - out_channels, - kernel_size, - nonlinearity='tanh', - bias=True, - stride=1, - dilation=1, - groups=1 + in_channels: int, + out_channels: int, + kernel_size: Union[int, Sequence[int]], + nonlinearity: str='tanh', + bias: bool=True, + stride: Union[int, Sequence[int]]=1, + dilation: Union[int, Sequence[int]]=1, + groups: int=1 ): if nonlinearity == 'tanh': mode = 'RNN_TANH' @@ -623,13 +745,13 @@ def __init__(self, class Conv1dLSTMCell(ConvRNNCellBase): def __init__(self, - in_channels, - out_channels, - kernel_size, - bias=True, - stride=1, - dilation=1, - groups=1 + in_channels: int, + out_channels: int, + kernel_size: Union[int, Sequence[int]], + bias: bool=True, + stride: Union[int, Sequence[int]]=1, + dilation: Union[int, Sequence[int]]=1, + groups: int=1 ): super().__init__( mode='LSTM', @@ -646,13 +768,13 @@ def __init__(self, class Conv1dPeepholeLSTMCell(ConvRNNCellBase): def __init__(self, - in_channels, - out_channels, - kernel_size, - bias=True, - stride=1, - dilation=1, - groups=1 + in_channels: int, + out_channels: int, + kernel_size: Union[int, Sequence[int]], + bias: bool=True, + stride: Union[int, Sequence[int]]=1, + dilation: Union[int, Sequence[int]]=1, + groups: int=1 ): super().__init__( mode='PeepholeLSTM', @@ -669,13 +791,13 @@ def __init__(self, class Conv1dGRUCell(ConvRNNCellBase): def __init__(self, - in_channels, - out_channels, - kernel_size, - bias=True, - stride=1, - dilation=1, - groups=1 + in_channels: int, + out_channels: int, + kernel_size: Union[int, Sequence[int]], + bias: bool=True, + stride: Union[int, Sequence[int]]=1, + dilation: Union[int, Sequence[int]]=1, + groups: int=1 ): super().__init__( mode='GRU', @@ -692,14 +814,14 @@ def __init__(self, class Conv2dRNNCell(ConvRNNCellBase): def __init__(self, - in_channels, - out_channels, - kernel_size, - nonlinearity='tanh', - bias=True, - stride=1, - dilation=1, - groups=1 + in_channels: int, + out_channels: int, + kernel_size: Union[int, Sequence[int]], + nonlinearity: str='tanh', + bias: bool=True, + stride: Union[int, Sequence[int]]=1, + dilation: Union[int, Sequence[int]]=1, + groups: int=1 ): if nonlinearity == 'tanh': mode = 'RNN_TANH' @@ -722,13 +844,13 @@ def __init__(self, class Conv2dLSTMCell(ConvRNNCellBase): def __init__(self, - in_channels, - out_channels, - kernel_size, - bias=True, - stride=1, - dilation=1, - groups=1 + in_channels: int, + out_channels: int, + kernel_size: Union[int, Sequence[int]], + bias: bool=True, + stride: Union[int, Sequence[int]]=1, + dilation: Union[int, Sequence[int]]=1, + groups: int=1 ): super().__init__( mode='LSTM', @@ -745,13 +867,13 @@ def __init__(self, class Conv2dPeepholeLSTMCell(ConvRNNCellBase): def __init__(self, - in_channels, - out_channels, - kernel_size, - bias=True, - stride=1, - dilation=1, - groups=1 + in_channels: int, + out_channels: int, + kernel_size: Union[int, Sequence[int]], + bias: bool=True, + stride: Union[int, Sequence[int]]=1, + dilation: Union[int, Sequence[int]]=1, + groups: int=1 ): super().__init__( mode='PeepholeLSTM', @@ -768,13 +890,13 @@ def __init__(self, class Conv2dGRUCell(ConvRNNCellBase): def __init__(self, - in_channels, - out_channels, - kernel_size, - bias=True, - stride=1, - dilation=1, - groups=1 + in_channels: int, + out_channels: int, + kernel_size: Union[int, Sequence[int]], + bias: bool=True, + stride: Union[int, Sequence[int]]=1, + dilation: Union[int, Sequence[int]]=1, + groups: int=1 ): super().__init__( mode='GRU', @@ -791,14 +913,14 @@ def __init__(self, class Conv3dRNNCell(ConvRNNCellBase): def __init__(self, - in_channels, - out_channels, - kernel_size, - nonlinearity='tanh', - bias=True, - stride=1, - dilation=1, - groups=1 + in_channels: int, + out_channels: int, + kernel_size: Union[int, Sequence[int]], + nonlinearity: str='tanh', + bias: bool=True, + stride: Union[int, Sequence[int]]=1, + dilation: Union[int, Sequence[int]]=1, + groups: int=1 ): if nonlinearity == 'tanh': mode = 'RNN_TANH' @@ -821,13 +943,13 @@ def __init__(self, class Conv3dLSTMCell(ConvRNNCellBase): def __init__(self, - in_channels, - out_channels, - kernel_size, - bias=True, - stride=1, - dilation=1, - groups=1 + in_channels: int, + out_channels: int, + kernel_size: Union[int, Sequence[int]], + bias: bool=True, + stride: Union[int, Sequence[int]]=1, + dilation: Union[int, Sequence[int]]=1, + groups: int=1 ): super().__init__( mode='LSTM', @@ -844,13 +966,13 @@ def __init__(self, class Conv3dPeepholeLSTMCell(ConvRNNCellBase): def __init__(self, - in_channels, - out_channels, - kernel_size, - bias=True, - stride=1, - dilation=1, - groups=1 + in_channels: int, + out_channels: int, + kernel_size: Union[int, Sequence[int]], + bias: bool=True, + stride: Union[int, Sequence[int]]=1, + dilation: Union[int, Sequence[int]]=1, + groups: int=1 ): super().__init__( mode='PeepholeLSTM', @@ -867,13 +989,13 @@ def __init__(self, class Conv3dGRUCell(ConvRNNCellBase): def __init__(self, - in_channels, - out_channels, - kernel_size, - bias=True, - stride=1, - dilation=1, - groups=1 + in_channels: int, + out_channels: int, + kernel_size: Union[int, Sequence[int]], + bias: bool=True, + stride: Union[int, Sequence[int]]=1, + dilation: Union[int, Sequence[int]]=1, + groups: int=1 ): super().__init__( mode='GRU', diff --git a/code/demo.py b/code/demo.py index 8748706..933dc3d 100644 --- a/code/demo.py +++ b/code/demo.py @@ -22,6 +22,7 @@ from skimage import transform as tf from copy import deepcopy from scipy.spatial import procrustes +import imageio import dlib @@ -248,14 +249,14 @@ def test(): for indx in range(fake_ims.size(1)): fake_im = fake_ims[:,indx] fake_store = fake_im.permute(0,2,3,1).data.cpu().numpy()[0] - scipy.misc.imsave("{}/{:05d}.png".format(os.path.join('../', 'temp', 'img') ,indx ), fake_store) + imageio.imwrite("{}/{:05d}.png".format(os.path.join('../', 'temp', 'img') ,indx ), fake_store) m = ms[:,indx] att = atts[:,indx] m = m.permute(0,2,3,1).data.cpu().numpy()[0] att = att.data.cpu().numpy()[0,0] - scipy.misc.imsave("{}/{:05d}.png".format(os.path.join('../', 'temp', 'motion' ) ,indx ), m) - scipy.misc.imsave("{}/{:05d}.png".format(os.path.join('../', 'temp', 'attention') ,indx ), att) + imageio.imwrite("{}/{:05d}.png".format(os.path.join('../', 'temp', 'motion' ) ,indx ), m) + imageio.imwrite("{}/{:05d}.png".format(os.path.join('../', 'temp', 'attention') ,indx ), att) print ( 'In total, generate {:d} images, cost time: {:03f} seconds'.format(fake_ims.size(1), time.time() - t) ) save_name = config.save_name diff --git a/code/models.py b/code/models.py index 2df67e7..1da1598 100644 --- a/code/models.py +++ b/code/models.py @@ -241,12 +241,12 @@ def __init__(self,input_nc = 3, output_nc = 3,ngf = 64, use_dropout=True, use_bi self.base = nn.Sequential(*model) model = [] - model += [nn.Conv2d(ngf/2, output_nc, kernel_size=7, padding=3)] + model += [nn.Conv2d(ngf//2, output_nc, kernel_size=7, padding=3)] model += [nn.Tanh()] self.generator_color = nn.Sequential(*model) model = [] - model += [nn.Conv2d(ngf/2, 1, kernel_size=7, padding=3)] + model += [nn.Conv2d(ngf//2, 1, kernel_size=7, padding=3)] model += [nn.Sigmoid()] self.generator_attention = nn.Sequential(*model) @@ -266,7 +266,7 @@ def forward(self,image, landmarks, example_landmark ): lstm_input = list() lmark_atts = list() - for step_t in xrange(landmarks.size(1)): + for step_t in range(landmarks.size(1)): landmark = landmarks[:,step_t,:] landmark.data = landmark.data.contiguous() landmark = self.landmark_encoder(landmark.view(landmark.size(0), -1)) @@ -286,7 +286,7 @@ def forward(self,image, landmarks, example_landmark ): outputs = [] atts = [] colors = [] - for step_t in xrange(landmarks.size(1)): + for step_t in range(landmarks.size(1)): input_t = lstm_output[:,step_t,:,:,:] v_feature1 = self.generator1(input_t) v_feature1_f = image_feature1 * (1- lmark_atts[:,step_t,:,:,:] ) + v_feature1 * lmark_atts[:,step_t,:,:,:] diff --git a/dockerfile b/dockerfile new file mode 100644 index 0000000..68b8269 --- /dev/null +++ b/dockerfile @@ -0,0 +1,15 @@ +FROM pytorch/pytorch:1.11.0-cuda11.3-cudnn8-devel + +# uncomment this if you have trouble downloading packages +# RUN rm /etc/apt/sources.list.d/cuda.list && \ +# rm /etc/apt/sources.list.d/nvidia-ml.list && \ +# sed -i "s@http://.*archive.ubuntu.com@https://mirrors.tuna.tsinghua.edu.cn@g" /etc/apt/sources.list && \ +# sed -i "s@http://.*security.ubuntu.com@https://mirrors.tuna.tsinghua.edu.cn@g" /etc/apt/sources.list && \ +# pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple + +RUN apt-get -y update --fix-missing && \ + apt-get install -y libglib2.0-0 libxrender1 ffmpeg libsm6 cmake && \ + pip install numpy matplotlib tqdm dlib opencv-python scipy librosa typing python_speech_features scikit-image imageio + +RUN mkdir /workspace/ATVGnet +WORKDIR /workspace/ATVGnet/code \ No newline at end of file