0

这是我的代码

使用 75% 的

用于训练的数据,其余 25% 用于测试

(trainX, testX, trainY, testY) = train_test_split(data,
    labels, test_size=0.25, random_state=42)

将标签从整数转换为向量

trainY = to_categorical(trainY, num_classes=5)
testY = to_categorical(testY, num_classes=5)

它显示了这种类型的错误如何修复和解决它

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'
4

1 回答 1

0

看起来您正在尝试从链接https://github.com/robinreni96/Font_Recognition-DeepFont运行代码。如果您使用的是 windows 机器,则需要在数据集准备中进行一项更改:data_path = "font_patch\\" 因为 "os.path.sep" 在 windows 中是 "\"。

于 2020-04-16T07:05:50.620 回答