【问题标题】:Importing imdb dataset from keras dataset从 keras 数据集导入 imdb 数据集
【发布时间】:2021-05-30 12:34:58
【问题描述】:

尝试加载 keras imdb 数据集时出现错误 这是我的代码

import tensorflow as tf
from tensorflow import keras
import numpy as np

data = keras.datasets.imdb

(train_data, train_label), (test_data, test_label) = data.load_data(num_words=10000)

这是我得到的错误

<string>:6: VisibleDeprecationWarning: Creating an ndarray from ragged nested sequences (which is a list-or-tuple of lists-or-tuples-or ndarrays with different lengths or shapes) is deprecated. If you meant to do this, you must specify 'dtype=object' when creating the ndarray
/usr/local/lib/python3.7/dist-packages/tensorflow/python/keras/datasets/imdb.py:159: VisibleDeprecationWarning: Creating an ndarray from ragged nested sequences (which is a list-or-tuple of lists-or-tuples-or ndarrays with different lengths or shapes) is deprecated. If you meant to do this, you must specify 'dtype=object' when creating the ndarray
  x_train, y_train = np.array(xs[:idx]), np.array(labels[:idx])
/usr/local/lib/python3.7/dist-packages/tensorflow/python/keras/datasets/imdb.py:160: VisibleDeprecationWarning: Creating an ndarray from ragged nested sequences (which is a list-or-tuple of lists-or-tuples-or ndarrays with different lengths or shapes) is deprecated. If you meant to do this, you must specify 'dtype=object' when creating the ndarray
  x_test, y_test = np.array(xs[idx:]), np.array(labels[idx:])

【问题讨论】:

  • 这看起来像一个警告

标签: python numpy tensorflow keras neural-network


【解决方案1】:
VisibleDeprecationWarning: Creating an ndarray from ragged nested sequences (which is a list-or-tuple of lists-or-tuples-or ndarrays with different lengths or shapes) is deprecated. If you meant to do this, you must specify 'dtype=object' when creating the ndarray

这些是弃用警告,可以忽略。这些警告不会停止执行其余代码。

【讨论】:

  • 是的,这是真的,但是当我执行下一行代码时word_index = imdb.get_word_index() 我收到此错误NameError Traceback (most recent call last) &lt;ipython-input-10-6bb83d261f26&gt; in &lt;module&gt; ----&gt; 1 word_index = imdb.get_word_index() NameError: name 'imdb' is not defined
  • 此导入将对您有所帮助,from tensorflow.keras.datasets import imbd。谢谢!
猜你喜欢
  • 1970-01-01
  • 2018-08-11
  • 1970-01-01
  • 1970-01-01
  • 2019-12-19
  • 2017-08-06
  • 2020-01-26
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多