2017-08-25 273 views
1

net.forward運行我使用Python IDE spyder3.2.1在anaconda2,與python2.7,ubuntu14.04Spyder的只是 「內核去世後,重新啓動」 當我在pytorch

代碼如下只是簡單的:

import torch 
from torch.autograd import Variable 
import torch.nn as nn 
import torch.nn.functional as F 
import numpy as np 

""" 
input:[batch_size,in_channel,height,width] 
kernel:[out_channel,in_channel,kh,kw] 
""" 
class Net(nn.Module): 

    def __init__(self): 
     super(Net, self).__init__() 
     # 1 input image channel, 6 output channels, 5x5 square convolution 
     # kernel 
     self.conv1 = nn.Conv2d(1, 6, 5) 
     #(28-5+1)/2=12 
     self.conv2 = nn.Conv2d(6, 16, 5) 
     #(12-5+1)/2=4 
     # an affine operation: y = Wx + b 
     self.fc1 = nn.Linear(16 * 5 * 5, 120) 
     self.fc2 = nn.Linear(120, 84) 
     self.fc3 = nn.Linear(84, 10) 

    def forward(self, x): 
     # Max pooling over a (2, 2) window 
     x = F.max_pool2d(F.relu(self.conv1(x)), (2, 2)) 
     # If the size is a square you can only specify a single number 
     print "after conv1 size is {}".format(x.size()) 
     x = F.max_pool2d(F.relu(self.conv2(x)), 2) 
     print "after conv2 size is {}".format(x.size()) 
     x = x.view(-1, self.num_flat_features(x)) 
     x = F.relu(self.fc1(x)) 
     x = F.relu(self.fc2(x)) 
     x = self.fc3(x) 
     return x 

    def num_flat_features(self, x): 
     size = x.size()[1:] # all dimensions except the batch dimension 
     num_features = 1 
     for s in size: 
      num_features *= s 
     return num_features 

net = Net() 
print(net) 

print "hello wrold" 
input = Variable(torch.Tensor(np.random.randint(1,10,size=(1,1,32,32)))) 
print net.forward(input) 

當我使用jupyter筆記本或控制檯,它運行正常,它表示代碼沒有錯誤。
但是當我使用它的Spyder,它只是掛起喜歡這樣的:
enter image description here
As I am not allowed to embed the error image: it says "Kernel died, restarting"

我只是儘量縮小我的代碼找到問題的所在。

這個問題絕對是圍繞着一開始F.max_pool2d(),在轉發方法功能。

但我搜索了很多後,我仍然不知道如何解決它。

暢達列表:

alabaster     0.7.10     py27_0 
anaconda     4.4.0    np112py27_0 
anaconda-client   1.6.3     py27_0 
anaconda-navigator  1.6.2     py27_0 
anaconda-project   0.6.0     py27_0 
asn1crypto    0.22.0     py27_0 
astroid     1.4.9     py27_0 
astroid     1.5.3      <pip> 
astropy     1.3.2    np112py27_0 
Babel      2.5.0      <pip> 
babel      2.4.0     py27_0 
backports     1.0      py27_0 
backports.functools-lru-cache 1.4      <pip> 
backports.weakref   1.0rc1     <pip> 
backports_abc    0.5      py27_0 
beautifulsoup4   4.6.0     py27_0 
bitarray     0.8.1     py27_0 
blaze      0.10.1     py27_0 
bleach     1.5.0     py27_0 
bleach     2.0.0      <pip> 
bokeh      0.12.5     py27_1 
boto      2.46.1     py27_0 
bottleneck    1.2.1    np112py27_0 
cairo      1.14.8      0 
cdecimal     2.3      py27_2 
certifi     2017.7.27.1    <pip> 
cffi      1.10.0     py27_0 
chardet     3.0.3     py27_0 
chardet     3.0.4      <pip> 
click      6.7      py27_0 
cloudpickle    0.2.2     py27_0 
clyent     1.2.2     py27_0 
colorama     0.3.9     py27_0 
conda      4.3.21     py27_0 
conda-env     2.6.0       0 
configparser    3.5.0     py27_0 
contextlib2    0.5.5     py27_0 
cryptography    1.8.1     py27_0 
curl      7.52.1      0 
cycler     0.10.0     py27_0 
cython     0.25.2     py27_0 
cytoolz     0.8.2     py27_0 
dask      0.14.3     py27_1 
datashape     0.5.4     py27_0 
dbus      1.10.10      0 
decorator     4.0.11     py27_0 
distributed    1.16.3     py27_0 
docutils     0.14      <pip> 
docutils     0.13.1     py27_0 
entrypoints    0.2.2     py27_1 
entrypoints    0.2.3      <pip> 
enum34     1.1.6     py27_0 
et_xmlfile    1.0.1     py27_0 
expat      2.1.0       0 
fastcache     1.0.2     py27_1 
flask      0.12.2     py27_0 
flask-cors    3.0.2     py27_0 
fontconfig    2.12.1      3 
freetype     2.5.5       2 
funcsigs     1.0.2     py27_0 
functools32    3.2.3.2     py27_0 
futures     3.1.1     py27_0 
get_terminal_size   1.0.0     py27_0 
gevent     1.2.1     py27_0 
glib      2.50.2      1 
greenlet     0.4.12     py27_0 
grin      1.2.1     py27_3 
gst-plugins-base   1.8.0       0 
gstreamer     1.8.0       0 
h5py      2.7.0    np112py27_0 
harfbuzz     0.9.39      2 
hdf5      1.8.17      1 
heapdict     1.0.0     py27_1 
html5lib     0.999999999    <pip> 
html5lib     0.999     py27_0 
icu      54.1       0 
idna      2.5      py27_0 
idna      2.6      <pip> 
imagesize     0.7.1     py27_0 
ipaddress     1.0.18     py27_0 
ipykernel     4.6.1     py27_0 
ipython     5.3.0     py27_0 
ipython_genutils   0.2.0     py27_0 
ipywidgets    6.0.0     py27_0 
isort      4.2.5     py27_0 
isort      4.2.15     <pip> 
itsdangerous    0.24      py27_0 
jbig      2.1       0 
jdcal      1.3      py27_0 
jedi      0.10.2     py27_2 
jinja2     2.9.6     py27_0 
jpeg      9b       0 
jsonschema    2.6.0     py27_0 
jupyter     1.0.0     py27_3 
jupyter-client   5.1.0      <pip> 
jupyter_client   5.0.1     py27_0 
jupyter_console   5.1.0     py27_0 
jupyter_core    4.3.0     py27_0 
lazy-object-proxy   1.2.2     py27_0 
lazy-object-proxy   1.3.1      <pip> 
libffi     3.2.1       1 
libgcc     4.8.5       2 
libgfortran    3.0.0       1 
libiconv     1.14       0 
libpng     1.6.27      0 
libsodium     1.0.10      0 
libtiff     4.0.6       3 
libtool     2.4.2       0 
libxcb     1.12       1 
libxml2     2.9.4       0 
libxslt     1.1.29      0 
llvmlite     0.18.0     py27_0 
locket     0.2.0     py27_1 
lxml      3.7.3     py27_0 
Markdown     2.6.8      <pip> 
markupsafe    0.23      py27_2 
MarkupSafe    1.0      <pip> 
matplotlib    2.0.2    np112py27_0 
mccabe     0.6.1      <pip> 
mistune     0.7.4     py27_0 
mkl      2017.0.1      0 
mkl-service    1.1.2     py27_3 
mock      2.0.0      <pip> 
mpmath     0.19      py27_1 
msgpack-python   0.4.8     py27_0 
multipledispatch   0.4.9     py27_0 
navigator-updater   0.1.0     py27_0 
nbconvert     5.2.1      <pip> 
nbconvert     5.1.1     py27_0 
nbformat     4.4.0      <pip> 
nbformat     4.3.0     py27_0 
networkx     1.11      py27_0 
nltk      3.2.3     py27_0 
nose      1.3.7     py27_1 
notebook     5.0.0     py27_0 
numba      0.33.0    np112py27_0 
numexpr     2.6.2    np112py27_0 
numpy      1.12.1     py27_0 
numpy      1.13.1     <pip> 
numpydoc     0.6.0     py27_0 
numpydoc     0.7.0      <pip> 
odo      0.5.0     py27_1 
olefile     0.44      py27_0 
opencv     1.0.1      <pip> 
opencv-python    3.3.0.9     <pip> 
openpyxl     2.4.7     py27_0 
openssl     1.0.2l      0 
packaging     16.8      py27_0 
pandas     0.20.1    np112py27_0 
pandocfilters    1.4.1     py27_0 
pandocfilters    1.4.2      <pip> 
pango      1.40.3      1 
partd      0.3.8     py27_0 
path.py     10.3.1     py27_0 
pathlib2     2.3.0      <pip> 
pathlib2     2.2.1     py27_0 
patsy      0.4.1     py27_0 
pbr      3.1.1      <pip> 
pcre      8.39       1 
pep8      1.7.0     py27_0 
pexpect     4.2.1     py27_0 
pickleshare    0.7.4     py27_0 
pillow     4.1.1     py27_0 
pip      9.0.1     py27_1 
pixman     0.34.0      0 
ply      3.10      py27_0 
prompt_toolkit   1.0.14     py27_0 
protobuf     3.3.0      <pip> 
psutil     5.2.2     py27_0 
ptyprocess    0.5.1     py27_0 
py      1.4.33     py27_0 
pycairo     1.10.0     py27_0 
pycodestyle    2.3.1      <pip> 
pycosat     0.6.2     py27_0 
pycparser     2.17      py27_0 
pycrypto     2.6.1     py27_6 
pycurl     7.43.0     py27_2 
pyflakes     1.5.0     py27_0 
pyflakes     1.6.0      <pip> 
pygments     2.2.0     py27_0 
pylint     1.6.4     py27_1 
pylint     1.7.2      <pip> 
pylzma     0.4.9.post0    <pip> 
pyodbc     4.0.16     py27_0 
PyOpenGL     3.1.0      <pip> 
pyopenssl     17.0.0     py27_0 
pyparsing     2.1.4     py27_0 
pyqt      5.6.0     py27_2 
pytables     3.3.0    np112py27_0 
pytest     3.0.7     py27_0 
python     2.7.13      0 
python-dateutil   2.6.1      <pip> 
python-dateutil   2.6.0     py27_0 
pytz      2017.2     py27_0 
pywavelets    0.5.2    np112py27_0 
pyyaml     3.12      py27_0 
pyzmq      16.0.2     py27_0 
qt      5.6.2       4 
qtawesome     0.4.4     py27_0 
qtconsole     4.3.0     py27_0 
qtconsole     4.3.1      <pip> 
qtpy      1.2.1     py27_0 
QtPy      1.3.1      <pip> 
readline     6.2       2 
requests     2.18.4     <pip> 
requests     2.14.2     py27_0 
rope      0.10.7     <pip> 
rope      0.9.4     py27_1 
ruamel_yaml    0.11.14     py27_1 
scandir     1.5      py27_0 
scikit-image    0.13.0    np112py27_0 
scikit-learn    0.18.1    np112py27_1 
scipy      0.19.0    np112py27_0 
seaborn     0.7.1     py27_0 
setuptools    27.2.0     py27_0 
setuptools    36.2.7     <pip> 
simplegeneric    0.8.1     py27_1 
singledispatch   3.4.0.3     py27_0 
sip      4.18      py27_0 
six      1.10.0     py27_0 
snowballstemmer   1.2.1     py27_0 
sortedcollections   0.5.3     py27_0 
sortedcontainers   1.5.7     py27_0 
Sphinx     1.6.3      <pip> 
sphinx     1.5.6     py27_0 
sphinxcontrib-websupport 1.0.1      <pip> 
spyder     3.2.1      <pip> 
spyder     3.1.4     py27_0 
sqlalchemy    1.1.9     py27_0 
sqlite     3.13.0      0 
ssl_match_hostname  3.4.0.2     py27_1 
statsmodels    0.8.0    np112py27_0 
subprocess32    3.2.7     py27_0 
sympy      1.0      py27_0 
tblib      1.3.2     py27_0 
tensorflow    1.2.1      <pip> 
tensorlayer    1.6.0      <pip> 
terminado     0.6      py27_0 
testpath     0.3.1      <pip> 
testpath     0.3      py27_0 
tk      8.5.18      0 
toolz      0.8.2     py27_0 
torch-0.2.0    1       <pip> 
torchvision    0.1.9      <pip> 
tornado     4.5.1     py27_0 
tqdm      4.15.0     <pip> 
traitlets     4.3.2     py27_0 
typing     3.6.2      <pip> 
unicodecsv    0.14.1     py27_0 
unixodbc     2.3.4       0 
urllib3     1.22      <pip> 
wcwidth     0.1.7     py27_0 
webencodings    0.5.1      <pip> 
werkzeug     0.12.2     py27_0 
wheel      0.29.0     py27_0 
widgetsnbextension  2.0.0     py27_0 
wrapt      1.10.11     <pip> 
wrapt      1.10.10     py27_0 
xlrd      1.0.0     py27_0 
xlsxwriter    0.9.6     py27_0 
xlwt      1.2.0     py27_0 
xz      5.2.2       1 
yaml      0.1.6       0 
zeromq     4.1.5       0 
zict      0.1.2     py27_0 
zlib      1.2.8       3 
+0

你是怎麼安裝PyTorch的?從soumith的Anaconda頻道?您是否嘗試過使用Python 3.6? –

+0

我通過** source安裝**重新安裝pytorch,並且一切順利 –

回答

0

Spyder的開發商在這裏)我不知道爲什麼發生這種情況,但我在問題追蹤器打開an issue所以我們不要忘了看看它在未來。

更新:此問題已由OP通過更新PyTorch解決。

相關問題