当我尝试从tflearn使用to_categorical时,我总是得到一个typeError。输出错误为:`
 trainY = to_categorical(y = trainY, nb_classes=2)
  File "C:\Users\saleh\Anaconda3\lib\site-packages\tflearn\data_utils.py", line 46, in to_categorical
    return (y[:, None] == np.unique(y)).astype(np.float32)
TypeError: list indices must be integers or slices, not tuple这是我正在尝试运行的可重现代码:
import tflearn
from tflearn.data_utils import to_categorical
from tflearn.datasets import imdb
#IMDB dataset loading
train, test, _ = imdb.load_data(path = 'imdb.pkl', n_words = 10000, valid_portion = 0.1)
trainX, trainY = train
testX, testY = test
#converting labels to binary vectors
trainY = to_categorical(y = trainY, nb_classes=2)  # **This is where I get the error**
testY = to_categorical(y = testY, nb_classes=2)发布于 2017-10-30 01:30:06
无法重现您的错误:
import tflearn
from tflearn.data_utils import to_categorical
from tflearn.datasets import imdb
train, test, _ = imdb.load_data(path = 'imdb.pkl', n_words = 10000, valid_portion = 0.1)
trainX, trainY = train
testX, testY = test
trainY[0:5]
# [0, 0, 0, 1, 0]
trainY = to_categorical(y = trainY, nb_classes=2) 
trainY[0:5]
# array([[ 1.,  0.],
#        [ 1.,  0.],
#        [ 1.,  0.],
#        [ 0.,  1.],
#        [ 1.,  0.]])系统配置:
更新:最近的一些TFLearn提交似乎破坏了to_categorical -请参阅here和here。我建议卸载您当前的版本,并安装最新的带有pip install tflearn的稳定版 one (这实际上就是我在上面所做的)。
https://stackoverflow.com/questions/47001784
复制相似问题