首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >tflearn to_categorical类型错误

tflearn to_categorical类型错误
EN

Stack Overflow用户
提问于 2017-10-29 23:11:51
回答 1查看 427关注 0票数 0

当我尝试从tflearn使用to_categorical时,我总是得到一个typeError。输出错误为:`

代码语言:javascript
运行
复制
 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

这是我正在尝试运行的可重现代码:

代码语言:javascript
运行
复制
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)
EN

Stack Overflow用户

发布于 2017-10-30 01:30:06

无法重现您的错误:

代码语言:javascript
运行
复制
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.]])

系统配置:

  • Python 2.7.12
  • Tensorflow 1.3.0
  • TFLearn 0.3.2
  • Ubuntu 16.04

更新:最近的一些TFLearn提交似乎破坏了to_categorical -请参阅herehere。我建议卸载您当前的版本,并安装最新的带有pip install tflearn稳定版 one (这实际上就是我在上面所做的)。

票数 1
EN
查看全部 1 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/47001784

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档