How to train and test dataset and how to convert the labels from integers to vectors in jupyter notebook?

倖福魔咒の 提交于 2020-04-18 05:29:07

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!