问题
Here is my code
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)
convert the labels from integers to vectors
trainY = to_categorical(trainY, num_classes=5)
testY = to_categorical(testY, num_classes=5)
And it show this type of error how to fix and solve it
TypeError Traceback (most recent call last)
<ipython-input-13-513dfa9190a2> in <module>
1 # convert the labels from integers to vectors
----> 2 trainY = to_categorical(trainY, num_classes=5)
3 testY = to_categorical(testY, num_classes=5)
~\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:
looks like your are trying to run code from the link https://github.com/robinreni96/Font_Recognition-DeepFont. If you are using windows machine, you need to make one change in dataset preparation: data_path = "font_patch\\" because "os.path.sep" is "\" in windows.
来源:https://stackoverflow.com/questions/60353834/how-to-train-and-test-dataset-and-how-to-convert-the-labels-from-integers-to-vec