Cannot reproduce your error:
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.]])
System configuration:
- Python 2.7.12
- Tensorflow 1.3.0
- TFLearn 0.3.2
- Ubuntu 16.04
UPDATE: It seems that some recent TFLearn commit has broken to_categorical
- see here and here. I suggest to uninstall your current version and install the latest stable one with pip install tflearn
(this is actually what I have done myself above).
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…