2

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.

Community
  • 1
  • 1
KEN
  • 49
  • 1
  • 2
  • 9
  • this can help https://stackoverflow.com/a/45726867/7825115 – Kallz Aug 31 '17 at 04:14
  • Does this answer your question? [Why do I get AttributeError: 'NoneType' object has no attribute 'something'?](https://stackoverflow.com/questions/8949252/why-do-i-get-attributeerror-nonetype-object-has-no-attribute-something) – Ulrich Eckhardt Jan 05 '22 at 18:09

2 Answers2

1

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)
1

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)
Hejun
  • 366
  • 2
  • 9