How to solve this problem in python jupyter notebo

2020-05-09 09:29发布

问题:

I am trying to run. But this error occurs

TypeError: int() argument must be a string, a bytes-like object or a number, not 'NoneType'

Here is code

data = np.asarray(data, dtype="float") / 255.0
labels = np.array(labels)
print("Success")
# partition the data into training and testing splits using 75% of
# the data for training and the remaining 25% for testing
(trainX, testX, trainY, testY) = train_test_split(data,
    labels, test_size=0.25, random_state=42)

#this is run successfully but when this part of code run then always error will occur

# convert the labels from integers to vectors
trainY =keras.utils.to_categorical(trainY, num_classes=2, dtype='float32')
testY = keras.utils.to_categorical(testY, num_classes=2, dtype='float32')
print(type(trainY))
print(type(testY))

and this type of error is occur

<ipython-input-12-a1259f490078> in <module>
      1 # convert the labels from integers to vectors
----> 2 trainY =keras.utils.to_categorical(trainY, num_classes=2, dtype='float32')
      3 testY = keras.utils.to_categorical(testY, num_classes=2, dtype='float32')
      4 print(type(trainY))
      5 print(type(testY))

~\Anaconda3\lib\site-packages\keras\utils\np_utils.py in to_categorical(y, num_classes, dtype)
     41     """
     42 
---> 43     y = np.array(y, dtype='int')
     44     input_shape = y.shape
     45     if input_shape and input_shape[-1] == 1 and len(input_shape) > 1:

TypeError: int() argument must be a string, a bytes-like object or a number, not 'NoneType'

回答1:

Refer to my answer in https://stackoverflow.com/a/61244517/4442496. This should help if you are using windows machine