Reputation: 49
i run this code.
import numpy as np
import matplotlib.pyplot as plt
from PIL import Image
X_train = plt.imread('00_0.9944__20150716_131647_04249_074.raw_color.bmp')
type(X_train)
X_train = X_train.resize((32, 32))
X_train = X_train.reshape((len(X_train), 3, 32, 32))
then, it throws
X_train = X_train.reshape((len(X_train), 3, 32, 32))
AttributeError: 'NoneType' object has no attribute 'reshape'
using img size is 207x209. Please help me. Thank you.
Upvotes: 2
Views: 17280
Reputation: 376
only the type of array can use reshape() and it can not change the number of the data your array contains. Maybe you can try something like this:
import numpy as np
from PIL import Image
import matplotlib as plt
x_train = Image.open('skyscraper.jpg')
x_train = x_train.resize((32,32))
x_train = np.array(x_train)
x_train = x_train.reshape((3,32,32))
print(x_train)
Upvotes: 1
Reputation: 53
It is possible to return a value of type None, check the type of X_train
in the following lines:
X_train = X_train.resize((32, 32))
type(X_train)
X_train = X_train.reshape((len(X_train), 3, 32, 32))
type(X_train)
Upvotes: 1