Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/285.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何使用Colab导入imdb数据集?_Python_Tensorflow_Keras_Attributeerror_Imdb - Fatal编程技术网

Python 如何使用Colab导入imdb数据集?

Python 如何使用Colab导入imdb数据集?,python,tensorflow,keras,attributeerror,imdb,Python,Tensorflow,Keras,Attributeerror,Imdb,我正在尝试在CoLab平台上从keras导入imdb数据集 我得到了这个错误: AttributeError Traceback (most recent call last) /usr/local/lib/python3.6/dist-packages/keras/backend/tensorflow_backend.py in _get_default_graph() 65 try: ---> 66

我正在尝试在CoLab平台上从keras导入imdb数据集

我得到了这个错误:

AttributeError                            Traceback (most recent call last)
/usr/local/lib/python3.6/dist-packages/keras/backend/tensorflow_backend.py in _get_default_graph()
     65     try:
---> 66         return tf.get_default_graph()
     67     except AttributeError:
AttributeError:模块“
tensorflow
”没有属性“
get\u default\u graph

在处理上述异常期间,发生了另一个异常:

RuntimeError                              Traceback (most recent call last)
7 frames
/usr/local/lib/python3.6/dist-packages/keras/backend/tensorflow_backend.py in _get_default_graph()
     67     except AttributeError:
     68         raise RuntimeError(
---> 69             'It looks like you are trying to use '
     70             'a version of multi-backend Keras that '
     71             'does not support TensorFlow 2.0. We recommend '
RuntimeError:看起来您正在尝试使用不支持TensorFlow 2.0的多后端Keras版本。我们建议使用
tf.keras
,或者降级到TensorFlow 1.14

我正在使用的代码:

from tensorflow.compat.v1 import keras
from keras.datasets import imdb
(x_train, y_train), (x_test, y_test) = imdb.load_data(path="imdb.npz",
                                                  num_words=None,
                                                  skip_top=0,
                                                  maxlen=None,
                                                  seed=113,
                                                  start_char=1,
                                                  oov_char=2,
                                                  index_from=3)

您可以使用以下方法将IMDB数据集加载到TensorFlow中

1。使用tensorflow.keras.dataset:

import tensorflow
from tensorflow.keras.datasets import imdb 

(x_train, y_train), (x_test, y_test) = imdb.load_data(path="imdb.npz",
                                                  num_words=None,
                                                  skip_top=0,
                                                  maxlen=None,
                                                  seed=113,
                                                  start_char=1,
                                                  oov_char=2,
                                                  index_from=3) 
x\u列车
x\u测试

2。使用tensorflow_数据集:

import tensorflow_datasets as tfds
ds = tfds.load('imdb_reviews', split='train')

for ex in ds.take(4):
  print(ex)
样本数据:

{'label': <tf.Tensor: shape=(), dtype=int64, numpy=0>, 'text': <tf.Tensor: shape=(), dtype=string, numpy=b"This was an absolutely terrible movie. Don't be lured in by Christopher Walken or Michael Ironside. Both are great actors, but this must simply be their worst role in history. Even their great acting could not redeem this movie's ridiculous storyline. This movie is an early nineties US propaganda piece. The most pathetic scenes were those when the Columbian rebels were making their cases for revolutions. Maria Conchita Alonso appeared phony, and her pseudo-love affair with Walken was nothing but a pathetic emotional plug in a movie that was devoid of any real meaning. I am disappointed that there are movies like this, ruining actor's like Christopher Walken's good name. I could barely sit through it.">}
{'label': <tf.Tensor: shape=(), dtype=int64, numpy=0>, 'text': <tf.Tensor: shape=(), dtype=string, numpy=b'I have been known to fall asleep during films, but this is usually due to a combination of things including, really tired, being warm and comfortable on the sette and having just eaten a lot. However on this occasion I fell asleep because the film was rubbish. The plot development was constant. Constantly slow and boring. Things seemed to happen, but with no explanation of what was causing them or why. I admit, I may have missed part of the film, but i watched the majority of it and everything just seemed to happen of its own accord without any real concern for anything else. I cant recommend this film at all.'>}
{'label': <tf.Tensor: shape=(), dtype=int64, numpy=0>, 'text': <tf.Tensor: shape=(), dtype=string, numpy=b'Mann photographs the Alberta Rocky Mountains in a superb fashion, and Jimmy Stewart and Walter Brennan give enjoyable performances as they always seem to do. <br /><br />But come on Hollywood - a Mountie telling the people of Dawson City, Yukon to elect themselves a marshal (yes a marshal!) and to enforce the law themselves, then gunfighters battling it out on the streets for control of the town? <br /><br />Nothing even remotely resembling that happened on the Canadian side of the border during the Klondike gold rush. Mr. Mann and company appear to have mistaken Dawson City for Deadwood, the Canadian North for the American Wild West.<br /><br />Canadian viewers be prepared for a Reefer Madness type of enjoyable howl with this ludicrous plot, or, to shake your head in disgust.'>}
{'label': <tf.Tensor: shape=(), dtype=int64, numpy=1>, 'text': <tf.Tensor: shape=(), dtype=string, numpy=b'This is the kind of film for a snowy Sunday afternoon when the rest of the world can go ahead with its own business as you descend into a big arm-chair and mellow for a couple of hours. Wonderful performances from Cher and Nicolas Cage (as always) gently row the plot along. There are no rapids to cross, no dangerous waters, just a warm and witty paddle through New York life at its best. A family film in every sense and one that deserves the praise it received.'>}  
{'label':,'text':}
{'label':,'text':}
{'label':,'text':}
{'label':,'text':}

这也将具有与上述相同的拆分

您可以使用以下方法将IMDB数据集加载到TensorFlow中

1。使用tensorflow.keras.dataset:

import tensorflow
from tensorflow.keras.datasets import imdb 

(x_train, y_train), (x_test, y_test) = imdb.load_data(path="imdb.npz",
                                                  num_words=None,
                                                  skip_top=0,
                                                  maxlen=None,
                                                  seed=113,
                                                  start_char=1,
                                                  oov_char=2,
                                                  index_from=3) 
x\u列车
x\u测试

2。使用tensorflow_数据集:

import tensorflow_datasets as tfds
ds = tfds.load('imdb_reviews', split='train')

for ex in ds.take(4):
  print(ex)
样本数据:

{'label': <tf.Tensor: shape=(), dtype=int64, numpy=0>, 'text': <tf.Tensor: shape=(), dtype=string, numpy=b"This was an absolutely terrible movie. Don't be lured in by Christopher Walken or Michael Ironside. Both are great actors, but this must simply be their worst role in history. Even their great acting could not redeem this movie's ridiculous storyline. This movie is an early nineties US propaganda piece. The most pathetic scenes were those when the Columbian rebels were making their cases for revolutions. Maria Conchita Alonso appeared phony, and her pseudo-love affair with Walken was nothing but a pathetic emotional plug in a movie that was devoid of any real meaning. I am disappointed that there are movies like this, ruining actor's like Christopher Walken's good name. I could barely sit through it.">}
{'label': <tf.Tensor: shape=(), dtype=int64, numpy=0>, 'text': <tf.Tensor: shape=(), dtype=string, numpy=b'I have been known to fall asleep during films, but this is usually due to a combination of things including, really tired, being warm and comfortable on the sette and having just eaten a lot. However on this occasion I fell asleep because the film was rubbish. The plot development was constant. Constantly slow and boring. Things seemed to happen, but with no explanation of what was causing them or why. I admit, I may have missed part of the film, but i watched the majority of it and everything just seemed to happen of its own accord without any real concern for anything else. I cant recommend this film at all.'>}
{'label': <tf.Tensor: shape=(), dtype=int64, numpy=0>, 'text': <tf.Tensor: shape=(), dtype=string, numpy=b'Mann photographs the Alberta Rocky Mountains in a superb fashion, and Jimmy Stewart and Walter Brennan give enjoyable performances as they always seem to do. <br /><br />But come on Hollywood - a Mountie telling the people of Dawson City, Yukon to elect themselves a marshal (yes a marshal!) and to enforce the law themselves, then gunfighters battling it out on the streets for control of the town? <br /><br />Nothing even remotely resembling that happened on the Canadian side of the border during the Klondike gold rush. Mr. Mann and company appear to have mistaken Dawson City for Deadwood, the Canadian North for the American Wild West.<br /><br />Canadian viewers be prepared for a Reefer Madness type of enjoyable howl with this ludicrous plot, or, to shake your head in disgust.'>}
{'label': <tf.Tensor: shape=(), dtype=int64, numpy=1>, 'text': <tf.Tensor: shape=(), dtype=string, numpy=b'This is the kind of film for a snowy Sunday afternoon when the rest of the world can go ahead with its own business as you descend into a big arm-chair and mellow for a couple of hours. Wonderful performances from Cher and Nicolas Cage (as always) gently row the plot along. There are no rapids to cross, no dangerous waters, just a warm and witty paddle through New York life at its best. A family film in every sense and one that deserves the praise it received.'>}  
{'label':,'text':}
{'label':,'text':}
{'label':,'text':}
{'label':,'text':}

这也将具有与上述相同的拆分

问题和解决方案很清楚:RuntimeError:看起来您正在尝试使用不支持TensorFlow 2.0的多后端Keras版本。我们建议使用tf.keras,或者将其降级到TensorFlow 1.14。谢谢,但您能告诉我如何执行建议的解决方案吗?使用tf.keras,或者将keras升级到支持TensorFlow 2.0的版本(如keras 2.3.1),或者将TensorFlow降级到1.14/1.15问题和解决方案很清楚:RuntimeError:看起来您正在尝试使用不支持TensorFlow 2.0的多后端Keras版本。我们建议使用tf.keras,或者降级到TensorFlow 1.14。谢谢,但您能告诉我如何执行建议的解决方案吗?使用tf.keras,或者将keras升级到支持TensorFlow 2.0的版本(如keras 2.3.1),或者将TensorFlow降级到1.14/1。15@NibrasAbo Alzahab如果您的问题通过上述方法得到解决,请接受并投赞成票。@Nibras Abo Alzahab如果您的问题通过上述方法得到解决,请接受并投赞成票。