pytorch / pytorch Goto Github PK
View Code? Open in Web Editor NEWTensors and Dynamic neural networks in Python with strong GPU acceleration
Home Page: https://pytorch.org
License: Other
Tensors and Dynamic neural networks in Python with strong GPU acceleration
Home Page: https://pytorch.org
License: Other
pip install -r requirements.txt
pip install .
cmake is installed via homebrew
Processing /Users/awiltschko/Code/pytorch
Requirement already satisfied (use --upgrade to upgrade): pyyaml in /Users/awiltschko/anaconda/lib/python2.7/site-packages (from torch==0.1)
Installing collected packages: torch
Running setup.py install for torch ... error
Complete output from command /Users/awiltschko/anaconda/bin/python -u -c "import setuptools, tokenize;__file__='/var/folders/h2/_l96jjy96xb86z690kzcqmzh0000gn/T/pip-fURm_1-build/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /var/folders/h2/_l96jjy96xb86z690kzcqmzh0000gn/T/pip-435VCI-record/install-record.txt --single-version-externally-managed --compile:
running install
running build_deps
/private/var/folders/h2/_l96jjy96xb86z690kzcqmzh0000gn/T/pip-fURm_1-build/torch/_thnn/utils.py:1: RuntimeWarning: Parent module 'torch._thnn' not found while handling absolute import
import os
/private/var/folders/h2/_l96jjy96xb86z690kzcqmzh0000gn/T/pip-fURm_1-build/torch/_thnn/utils.py:2: RuntimeWarning: Parent module 'torch._thnn' not found while handling absolute import
import itertools
CMake Error at /usr/local/Cellar/cmake/3.2.3/share/cmake/Modules/CMakeDetermineCCompiler.cmake:57 (message):
Could not find compiler set in environment variable CC:
gcc-4.9.
Call Stack (most recent call first):
CMake Error: Error required internal CMake variable not set, cmake may be not be built correctly.
Missing variable is:
CMAKE_C_COMPILER_ENV_VAR
CMake Error: Error required internal CMake variable not set, cmake may be not be built correctly.
Missing variable is:
CMAKE_C_COMPILER
CMake Error: Could not find cmake module file: /private/var/folders/h2/_l96jjy96xb86z690kzcqmzh0000gn/T/pip-fURm_1-build/torch/lib/build/TH/CMakeFiles/3.2.3/CMakeCCompiler.cmake
CMake Error: Error required internal CMake variable not set, cmake may be not be built correctly.
Missing variable is:
CMAKE_CXX_COMPILER_ENV_VAR
CMake Error: Error required internal CMake variable not set, cmake may be not be built correctly.
Missing variable is:
CMAKE_CXX_COMPILER
CMake Error: Could not find cmake module file: /private/var/folders/h2/_l96jjy96xb86z690kzcqmzh0000gn/T/pip-fURm_1-build/torch/lib/build/TH/CMakeFiles/3.2.3/CMakeCXXCompiler.cmake
CMake Error in :
No CMAKE_C_COMPILER could be found.
Tell CMake where to find the compiler by setting the CMake cache entry
CMAKE_C_COMPILER to the full path to the compiler, or to the compiler name
if it is in the PATH.
CMake Error in :
No CMAKE_CXX_COMPILER could be found.
Tell CMake where to find the compiler by setting the CMake cache entry
CMAKE_CXX_COMPILER to the full path to the compiler, or to the compiler
name if it is in the PATH.
CMake Error: CMAKE_C_COMPILER not set, after EnableLanguage
CMake Error: CMAKE_CXX_COMPILER not set, after EnableLanguage
-- Configuring incomplete, errors occurred!
See also "/private/var/folders/h2/_l96jjy96xb86z690kzcqmzh0000gn/T/pip-fURm_1-build/torch/lib/build/TH/CMakeFiles/CMakeOutput.log".
----------------------------------------
Command "/Users/awiltschko/anaconda/bin/python -u -c "import setuptools, tokenize;__file__='/var/folders/h2/_l96jjy96xb86z690kzcqmzh0000gn/T/pip-fURm_1-build/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /var/folders/h2/_l96jjy96xb86z690kzcqmzh0000gn/T/pip-435VCI-record/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /var/folders/h2/_l96jjy96xb86z690kzcqmzh0000gn/T/pip-fURm_1-build/
CELoss tells one very little about the loss.
MSELoss and NLLLoss are okay, because MSE and NLL are common acronyms, but not CE
Postponed for next release
Have an intial attempt, and talk to Allan
Serveable via some Python REST API
figure out details for images and videos
Audio
wav2letter
DeepSpeech2 for maybe Switchboard or something (Ask Gabriel)
Sparse Models (ads?)
simple distributed trainer like torch-distlearn / torch-ipc / torch-thrift
Synchronous, asynchronous and Elastic SGD
Integrate with Andrew / Yangqing's MPI library when that's ready
Port image classification and seq2seq to this
error handling
Once #81 is fixed, we should disable OpenMP in the data loading worker processes. Otherwise, everything ends up much slower.
We should have full CUDA half tensor support for nn and autograd from the day one.
another good suggestion from Ross.
add device id / location to print of tensor / variable
One of the weird things, is that to create a cuda tensor of the same type and size on a different device, you now have to write:
with torch.cuda.device(3):
x = type(tensor)(tensor.size())
This does not work, because it places x on tensor's device:
with torch.cuda.device(3):
x = tensor.new(tensor.size())
We should probably allow explicitly choosing the device in the constructor and new functions:
x = torch.cuda.FloatTensor(foo.size(), device=3)
y = x.new(device=3)
y = x.type('torch.cuda.FloatTensor', device=3)
Basic losses like NLLLoss and CELoss need to accept targets that dont have requires_grad = False or volatile = True. Targets being backprop-less is the most common case, and we should default to that.
Instead of overloading the multiplication operator to do both element-wise and matrix-multiplication it would be nicer and much safer to just support Python's matrix multiplication operator (see PEP 465, A @ B
is the matrix product, A * B
the element-wise product).
on os x with anaconda 2.7:
>>> import torch
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/szagoruyko/anaconda/lib/python2.7/site-packages/torch/__init__.py", line 1, in <module>
from torch._C import *
ImportError: dlopen(/Users/szagoruyko/anaconda/lib/python2.7/site-packages/torch/_C.so, 2): Symbol not found: _THRefcountedMapAllocator
Referenced from: /Users/szagoruyko/anaconda/lib/python2.7/site-packages/torch/lib/libshm.dylib
Expected in: /Users/szagoruyko/torch/install/lib/libTH.dylib
in /Users/szagoruyko/anaconda/lib/python2.7/site-packages/torch/lib/libshm.dylib
ipython works fine
I think we could remove dampening parameter from SGD here https://github.com/pytorch/pytorch/blob/master/torch/optim/sgd.py#L10, it is confusing and changes momentum if used
Two problems:
>>> torch.set_num_threads(1)
__main__:1: RuntimeWarning: set_num_threads is a no-op - torch was compiled without OpenMP support
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
SystemError: <built-in function set_num_threads> returned NULL without setting an error
A common pattern in Lua torch is:
nn.Sequential().add_module(m1).add_module(m2)
Can we support this?
Also it would be nice if I didn't have to make up a name every time, can it be an optional second argument?
import torch
from torch.autograd import Variable
v = Variable(torch.ones(5, 5))
v[0]
...
RecursionError: maximum recursion depth exceeded
Right now, after you created a Container, you can assign modules at a later time to it like this:
container.add_module('linear', nn.Linear())
Instead, also allow this simpler interface:
container.linear = nn.Linear()
I have an unhealthy obsession with PEP8... Could viewAs
, expandAs
be renamed to view_as
, expand_as
, etc.?
I might even volunteer to make everything pass flake8 if you guys are okay with accepting a PR that does that.
A suggestion from Ross Girshick:
x = Variable(torch.ones(2, 2))
y = x + 2
z = y * y
Allow this instead of giving an error (current master):
z.backward()
This is needed for the advanced user, where one might need to choose a specific backend, or a particular algorithm / mode in cudnn.
save_variables=True
torch.cat
prints TODO
: torch.cat(torch.Tensor(128), torch.Tensor(128))
output tensor of incorrect size at /Users/soumith/code/pytorch/torch/lib/TH/generic/THTensorMath.c:1040
RuntimeError: out of range at /Users/soumith/anaconda/conda-bld/pytorch-0.1.4_1475478983079/work/torch/lib/TH/generic/THTensor.c:350
right now, losses return numbers.
This is a sync point and we should avoid this earlier in the scheme of things than push it in later.
Sometimes constructing a Tensor with a storage interprets the storage as the backing storage:
a = torch.IntTensor(torch.IntStorage([1,2,3]))
1
2
3
[torch.IntTensor of size 3]
But not if it's a LongStorage
a = torch.LongTensor(torch.LongStorage([1,2,3]))
(0,.,.) =
1.4059e+14 1.4059e+14 1.4059e+14
0.0000e+00 0.0000e+00 1.4059e+14
[torch.LongTensor of size 1x2x3]
This is because we want to allow constructions like:
a = torch.IntTensor([1,2,3])
b = torch.FloatTensor(a.size())
But we also want to allow things like:
a = torch.IntTensor([1,2,3])
b = torch.IntTensor(a.storage())
We should resolve this ambiguity, probably using keyword arguments. We probably need to require something like:
a = torch.XTensor(size=b.size())
a = torch.XTensor(storage=b.storage())
There is really no reason to support Python 2. Python 3 has been out for 8 years now. There are plenty of good articles written about this. Maintaining a dual codebase is a going to be a major pain and it prevents you from using a whole bunch of new Python 3 features (six
only gets you so far).
Right now, our checkpointing exists / works, but we've been thinking of rethinking it and having particular use-cases / goals to be covered.
Here are some things that need to be covered by the new checkpointing:
{ 'conv1.weight' : torch.FloatTensor(...), 'resblock1.conv3.bias' : torch.FloatTensor(...), ...}
Also requested by Ross.
Seems to make sense.
See tensorflow/tensorflow#256
one feedback talking to a few researchers and showing the design is that the optim API right now doesn't allow one to optimize a non parameter variable.
For example, when optimizing like neural-art maybe, but also a bunch of meta-optimization research (like learning to learning to learn).
We should consider making it optional to give model in the constructor, and allow .step to take in params to optimize
Traceback (most recent call last):
File "build.py", line 7, in <module>
with_cuda=False
File "/Users/soumith/anaconda/lib/python2.7/site-packages/torch/utils/ffi/__init__.py", line 127, in compile_extension
ffi.cdef(_typedefs + header_source);
File "/Users/soumith/anaconda/lib/python2.7/site-packages/cffi/api.py", line 105, in cdef
self._cdef(csource, override=override, packed=packed)
File "/Users/soumith/anaconda/lib/python2.7/site-packages/cffi/api.py", line 119, in _cdef
self._parser.parse(csource, override=override, **options)
File "/Users/soumith/anaconda/lib/python2.7/site-packages/cffi/cparser.py", line 299, in parse
self._internal_parse(csource)
File "/Users/soumith/anaconda/lib/python2.7/site-packages/cffi/cparser.py", line 304, in _internal_parse
ast, macros, csource = self._parse(csource)
File "/Users/soumith/anaconda/lib/python2.7/site-packages/cffi/cparser.py", line 260, in _parse
ast = _get_parser().parse(csource)
File "/Users/soumith/anaconda/lib/python2.7/site-packages/cffi/cparser.py", line 40, in _get_parser
_parser_cache = pycparser.CParser()
File "/Users/soumith/anaconda/lib/python2.7/site-packages/pycparser/c_parser.py", line 87, in __init__
outputdir=taboutputdir)
File "/Users/soumith/anaconda/lib/python2.7/site-packages/pycparser/c_lexer.py", line 66, in build
self.lexer = lex.lex(object=self, **kwargs)
File "/Users/soumith/anaconda/lib/python2.7/site-packages/pycparser/ply/lex.py", line 911, in lex
lexobj.readtab(lextab, ldict)
File "/Users/soumith/anaconda/lib/python2.7/site-packages/pycparser/ply/lex.py", line 233, in readtab
titem.append((re.compile(pat, lextab._lexreflags | re.VERBOSE), _names_to_funcs(func_name, fdict)))
File "/Users/soumith/anaconda/lib/python2.7/re.py", line 194, in compile
return _compile(pattern, flags)
File "/Users/soumith/anaconda/lib/python2.7/re.py", line 249, in _compile
p = sre_compile.compile(pattern, flags)
File "/Users/soumith/anaconda/lib/python2.7/sre_compile.py", line 583, in compile
"sorry, but this version only supports 100 named groups"
AssertionError: sorry, but this version only supports 100 named groups
Right now, apart from figuring out API changes around freezing parts of the graph, another problem is:
This is a huge pain point in Torch, and is actually a common use case for many.
Cover this use-case properly and provide an example.
repro:
print nn.ConcatTable().add(nn.Linear(1,6)).add(nn.Linear(1,5))
FAIL: test_ReLU (__main__.TestNN)
----------------------------------------------------------------------
Traceback (most recent call last):
File "test_nn.py", line 287, in <lambda>
setattr(TestNN, test_name, lambda self,test=test: test(self))
File "/data/users/soumith/pytorch/test/common_nn.py", line 533, in __call__
self._do_test(test_case, module, input)
File "test_nn.py", line 33, in _do_test
test_case.check_jacobian(module, input, self.jacobian_input)
File "/data/users/soumith/pytorch/test/common_nn.py", line 433, in check_jacobian
PRECISION
AssertionError: 0.20518362972049153 not less than or equal to 1e-05
ERROR: test_maskedSelect (__main__.TestTorch)
----------------------------------------------------------------------
Traceback (most recent call last):
File "test_torch.py", line 1887, in test_maskedSelect
self.assertEqual(dst, torch.Tensor(dst2), 0)
File "/data/users/soumith/pytorch/test/common.py", line 66, in assertEqual
max_err = max(max_err, abs(x[index] - y[index]))
TypeError: bad operand type for abs(): 'DoubleTensor'
In [141]: L = nn.Linear(10,10)
...: S = nn.Sequential()
...: S.add_module('a', L)
...: S.add_module('b', L)
...: len(list(S.parameters()))
...:
Out[141]: 4
Listing shared parameters multiple times seems wrong... because for example SGD will end up accumulating the gradients twice (I think).
Also from a theoretical point of view I would say this model only has 110 parameters, not 220.
----> 1 torch.FloatTensor(10).eq(torch.DoubleTensor(10))
ValueError: Invalid arguments! Got (DoubleTensor), but expected (real value) or (THTensor* other)
Request from Ross Girshick and quite a common use-case:
Have an example showcasing (and figure out changes in the API) to support:
Train a model, but say with the first K layers frozen.
tl;dr: how to freeze part of the graph
E.g. it would be nice if this worked:
a = torch.IntTensor(10)
b = torch.LongTensor(10)
a.eq(b)
Same with add, subtract, etc.
Allow different weight initialization schemes for conv2d and linear.
See: https://github.com/Kaixhin/nninit for some schemes.
Ubuntu 16.04, anaconda python 2.7, got this when trying to 'import torch'
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-1-c031d3dd82fc> in <module>()
----> 1 import torch
/opt/rocks/pytorch/torch/__init__.py in <module>()
----> 1 from torch._C import *
2 import sys
3 import math
4
5 _tensor_classes = set()
ImportError: No module named _C
OSX 10.11.5
Running multiprocessing tests
F..slibc++abi.dylib: terminating with uncaught exception of type std::__1::system_error: Protocol not supported
$ Error: std::exception at /Users/soumith/anaconda/conda-bld/pytorch-0.1.3_1473720667243/work/torch/lib/libshm/core.cpp:112
TESTS FAILED: pytorch-0.1.3-py27_9
Always deserializing onto device 0 is dangerous, because often device 0 doesn't have enough memory.
This requires some heuristics to get right (e.g. what if you deserialize onto a machine with different # of GPUS?) You can look at what we did in cunn. I think this is low-pri.
In [127]: with open('checkpoint4.pt', 'wb') as f:
...: pickle.dump(torch.FloatTensor(10).cuda(3), f)
...:
In [128]: with open('checkpoint4.pt', 'rb') as f:
...: obj = pickle.load(f)
...:
In [130]: obj.getDevice()
Out[130]: 0
In [27]: print(torch.FloatTensor(1).fill_(1).div(0))
---------------------------------------------------------------------------
OverflowError Traceback (most recent call last)
<ipython-input-27-811177cb15a4> in <module>()
----> 1 print(torch.FloatTensor(1).fill_(1).div(0))
/home/alerer/anaconda/lib/python2.7/site-packages/torch/Tensor.pyc in __str__(self)
85
86 def __str__(self):
---> 87 return TensorPrinting.printTensor(self)
88
89 def __iter__(self):
/home/alerer/anaconda/lib/python2.7/site-packages/torch/TensorPrinting.pyc in printTensor(self)
106 return '[{} with no dimension]\n'.format(torch.typename(self))
107 elif self.nDimension() == 1:
--> 108 strt = _printVector(self)
109 elif self.nDimension() == 2:
110 strt = _printMatrix(self)
/home/alerer/anaconda/lib/python2.7/site-packages/torch/TensorPrinting.pyc in _printVector(tensor)
96
97 def _printVector(tensor):
---> 98 fmt, scale, _ = _printformat(tensor.storage())
99 strt = ''
100 if scale != 1:
/home/alerer/anaconda/lib/python2.7/site-packages/torch/TensorPrinting.pyc in _printformat(storage)
25
26 scale = 1
---> 27 exp_max = int(exp_max)
28 if int_mode:
29 if exp_max > 9:
OverflowError: cannot convert float infinity to integer
torch.CudaFloatTensor().double() returns torch.DoubleTensor instead of torch.CudaDoubleTensor
Requests from M'aurelio and Sumit Chopra.
RNN Example with:
m = nn.Conv2d(16, 32, (3, 3))
input = autograd.Variable(torch.randn(3, 16, 10, 10))
m(input)
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-57-ad2f7eaad9e5> in <module>()
----> 1 m(input)
/home/soumith/local/miniconda2/lib/python2.7/site-packages/torch/nn/modules/module.pyc in __call__(self, *input)
64
65 def __call__(self, *input):
---> 66 result = self.forward(*input)
67 for hook in self.forward_hooks.values():
68 hook(self, input, result)
/home/soumith/local/miniconda2/lib/python2.7/site-packages/torch/nn/modules/conv.pyc in forward(self, input)
140 return func(input, self.weight)
141 else:
--> 142 return func(input, self.weight, self.bias)
143
144
/home/soumith/local/miniconda2/lib/python2.7/site-packages/torch/autograd/function.pyc in __call__(self, *input)
16
17 def __call__(self, *input):
---> 18 return self._do_forward(*input)
19
20 def save_for_backward(self, *tensors):
/home/soumith/local/miniconda2/lib/python2.7/site-packages/torch/autograd/function.pyc in _do_forward(self, *input)
44 self.previous_functions = [(arg.creator, id(arg)) for arg in input]
45
---> 46 raw_output = self.forward(*unpacked_input)
47 if not isinstance(raw_output, tuple):
48 raw_output = (raw_output,)
/home/soumith/local/miniconda2/lib/python2.7/site-packages/torch/nn/functions/thnn/auto.pyc in forward(self, input, *params)
134 self.save_for_backward(input, *params)
135
--> 136 getattr(self._backend, update_output.name)(self._backend.library_state, input, output, *args)
137 return output
138
ValueError: Invalid arguments! Got (int, FloatTensor, FloatTensor, DoubleTensor, DoubleTensor, FloatTensor, FloatTensor, int, int, int, int, int, int), but expected (int state, torch.FloatTensor input, torch.FloatTensor output, torch.FloatTensor weight, [torch.FloatTensor bias or None], torch.FloatTensor finput, torch.FloatTensor fgradInput, int kW, int kH, int dW, int dH, int padW, int padH)
print(net.output.numpy())
print(net.output)
outputs:
[[ 0.13239434 -0.29563415 -1.65602779 ..., 0.40573671 2.0148921
2.12263751]
[ 0.40269312 -0.46252817 -1.35247242 ..., 0.53116792 1.76924741
1.93715036]]
Traceback (most recent call last):
File "loader.py", line 94, in <module>
print(net.output)
File "/home/zagoruys/anaconda2/lib/python2.7/site-packages/torch/Tensor.py", line 87, in __str__
return TensorPrinting.printTensor(self)
File "/home/zagoruys/anaconda2/lib/python2.7/site-packages/torch/TensorPrinting.py", line 110, in printTensor
strt = _printMatrix(self)
File "/home/zagoruys/anaconda2/lib/python2.7/site-packages/torch/TensorPrinting.py", line 69, in _printMatrix
strt += ' '.join(fmt.format(val/scale) for val in self.select(0, l).narrow(0, firstColumn, lastColumn-firstColumn+1)) + '\n'
ValueError: Invalid arguments! Got (int, int, float), but expected (long dimension, long start, long length)
tbh I would rely on numpy for all printing
repro:
import torch
import torch.legacy.nn as nn
net = nn.Sequential()
net.add(nn.SpatialConvolution(3,3,3,3,1,1))
torch.save(net, open('model.pt7', 'wb'))
with gcc-6:
cc1plus: warning: command line option '-Wstrict-prototypes' is valid for C/ObjC but not for C++
cc1plus: warning: command line option '-Wstrict-prototypes' is valid for C/ObjC but not for C++
cc1plus: warning: command line option '-Wstrict-prototypes' is valid for C/ObjC but not for C++
cc1plus: warning: command line option '-Wstrict-prototypes' is valid for C/ObjC but not for C++
In file included from /Users/szagoruyko/research/rocks/pytorch/torch/csrc/generic/Storage.cpp:297:0,
from generic/Storage.cpp:1,
from torch/csrc/Storage.cpp:11:
/Users/szagoruyko/research/rocks/pytorch/torch/csrc/generic/StorageMethods.cpp: In function 'PyObject* THPLongStorage_fromBuffer(PyObject*, PyObject*, PyObject*)':
/Users/szagoruyko/research/rocks/pytorch/torch/csrc/generic/StorageMethods.cpp:138:34: error: invalid conversion from 'long int*' to 'int64_t* {aka long long int*}' [-fpermissive]
THP_decodeInt64Buffer(storage->data, src + offset, byte_order, count);
~~~~~~~~~^~~~
In file included from torch/csrc/Storage.cpp:8:0:
torch/csrc/byte_order.h:12:6: note: initializing argument 1 of 'void THP_decodeInt64Buffer(int64_t*, const uint8_t*, THPByteOrder, size_t)'
void THP_decodeInt64Buffer(int64_t* dst, const uint8_t* src, THPByteOrder order, size_t len);
^~~~~~~~~~~~~~~~~~~~~
x = torch.Storage(10)
y = x[1:-1]
#1
with open('file.t7', 'w+b') as f:
torch.save([x, y], f)
f.seek(0)
a, b = torch.load(f)
# a and b no longer share the same storage
#2
q = multiprocessing.Queue()
q.put([x, y])
a, b = q.get()
# a and b no longer share the same data
both cudnn and dataparallel pushes do:
import torch.cuda
On OSX, test_nn.py crashes.
Also, dataparallel should smoothly load and work even when you have no CUDA, so this should be fixed.
RuntimeError: indexing a tensor with an object of type tuple. The only supported types are integers, slices and torch.ByteTensor.
from torch.autograd import Variable
b = Variable(torch.randn(10, 20))
b[:,:5]
---------------------------------------------------------------------------
RuntimeError Traceback (most recent call last)
<ipython-input-9-039a3f3ae91a> in <module>()
----> 1 b[:,:5]
/Users/soumith/anaconda/lib/python2.7/site-packages/torch/autograd/variable.pyc in __getitem__(self, key)
55 if isinstance(key, Variable) and isinstance(key.data, torch.ByteTensor):
56 return MaskedSelect()(self, key)
---> 57 return Index(key)(self)
58
59 # TODO: setitem
/Users/soumith/anaconda/lib/python2.7/site-packages/torch/autograd/function.pyc in __call__(self, *input)
16
17 def __call__(self, *input):
---> 18 return self._do_forward(*input)
19
20 def save_for_backward(self, *tensors):
/Users/soumith/anaconda/lib/python2.7/site-packages/torch/autograd/function.pyc in _do_forward(self, *input)
48 self.previous_functions = [(arg.creator or arg, id(arg)) for arg in input]
49
---> 50 raw_output = self.forward(*unpacked_input)
51 if not isinstance(raw_output, tuple):
52 raw_output = (raw_output,)
/Users/soumith/anaconda/lib/python2.7/site-packages/torch/autograd/functions/tensor.pyc in forward(self, i)
15 def forward(self, i):
16 self.input_size = i.size()
---> 17 return i[self.index]
18
19 def backward(self, grad_output):
RuntimeError: indexing a tensor with an object of type tuple. The only supported types are integers, slices and torch.ByteTensor
Having the output of MaxUnpool2d
to be computed as follows is error-prone.
out_height = (input.size(2) - 1) * self.dh + self.kh - 2*self.padh
out_width = (input.size(3) - 1) * self.dw + self.kw - 2*self.padw
For some configurations of input
size and stride
/kernel size
, there are pixel loss in the boundaries due to integer division, so when unpooling we might end up by having accesses which are out of the output size defined by the above equation, or giving completely wrong results.
Here is a test case:
import torch
import torch.nn as nn
import torch.autograd as autograd
m = nn.MaxPool2d(3, stride=2, return_indices = True)
mu = nn.MaxUnpool2d(3, stride=2)
input_tensor = torch.rand(1, 1, 6, 6)
input_tensor[0][0][5][5] = 2
input = autograd.Variable(input_tensor)
output, indices = m.forward(input)
unpooled_output = mu.forward(output, indices)
Curiously, the segfault is doesn't happen all the time, but instead it just raises an out-of-range error, or the outputs max are not in the right position.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.