No module named theano.tensor.nnet
在使用Anaconda Navigator-jupyter notebook运行下面的python代码时,出现上述问题。
import theano
from theano.tensor.nnet import conv
import theano.tensor as T
解决方法:
在Anaconda – Environments中安装需要的theano组件。
注意:有时会因为网络问题,导致部分安装失败,可以多次尝试。
UserWarning: downsample module has been moved
在运行下面代码的时候,出现如下错误提示:
from theano.tensor.signal import downsample
解决方法:将上述代码改为:
from theano.tensor.signal import pool
# from theano.tensor.signal import downsample
同时,对于使用了下面代码的语句,也需要做一些改动。
pool_out = downsample.max_pool_2d(input, maxpool_shape, ignore_border=True)
# 改为:
pool_out = pool.pool_2d(input, maxpool_shape, ignore_border=True)
ImportError: No module named logistic_sgd
在运行下面的代码时,提示上面的错误信息:
from logistic_sgd import LogisticRegression, load_data
from mlp import HiddenLayer
解决方法:
在下面的网页中,复制相应的代码,并在jupyter运行文件的相同目录下,创建logistic_sgd.py和mlp.py文件:
文件目录如下:
python NameError: global name ‘__file__’ is not defined
在运行logistic_sgd.ipynb文件时,出现上述错误提示。出现错误的代码如下:
if data_dir == "" and not os.path.isfile(dataset):
# Check if dataset is in the data directory.
new_path = os.path.join(
os.path.split('__file__')[0], # __file__
"..",
"data",
dataset
)
if os.path.isfile(new_path) or data_file == 'mnist.pkl.gz':
解决方法:
I solved it by treating file as a string, i.e. put "__file__"
(together with the quotes!) instead of __file__.
This works fine for me:
wk_dir = os.path.dirname(os.path.realpath('__file__'))
Python: IOError: [Errno 2] No such file or directory
在python加载图片文件的时候,出现如上错误,代码如下:
img1 = Image.open(open('//home//rachel//Documents//ZJU_Projects//DL//Dataset//rachel.jpg'
解决方法:根据自己需要加载的文件路径,改为如下代码:
# open random image of dimensions 639x516
img_file = open('C:\\Users\\yitian.z\\Documents\\CNNDataset\\littledog.jpg', 'rb')
img = Image.open(img_file) #C:\Users\yitian.z\Documents\CNNDataset
ValueError: total size of new array must be unchanged
在运行下面代码时,出现错误:
img1 = Image.open(open('//home//rachel//Documents//ZJU_Projects//DL//Dataset//rachel.jpg'))
width1,height1 = img1.size
img1 = numpy.asarray(img1, dtype = 'float32')/256. # (height, width, 3)
# put image in 4D tensor of shape (1,3,height,width)
img1_rgb = img1.swapaxes(0,2).swapaxes(1,2).reshape(1,3,height1,width1) #(3,height,width)
解决方法:
# open random image of dimensions 639x516
img_file = open('C:\\Users\\yitian.z\\Documents\\CNNDataset\\littledog.jpg', 'rb')
img = Image.open(img_file) #C:\Users\yitian.z\Documents\CNNDataset
# img.show()
# print img.size
width, height = img.size
print width, height
# dimensions are (height, width, channel)
img = numpy.asarray(img, dtype = 'float64')/256. # (height, width, 3)
# put image in 4D tensor of shape (1, 3, height, width)
# img1_rgb = img1.swapaxes(0, 2)
# img1_rgb = img1_rgb.swapaxes(1, 2)
# img1_rgb = img1_rgb.reshape(1, 3, height1, width1) # (3, height, width)
cc = img.transpose(2, 0, 1)
img_ = img.transpose(2, 0, 1).reshape(1, 3, height, width)
filtered_img = f(img_)