模块“emnist”没有属性“列车图像”

2024-06-16 14:25:39 发布

您现在位置:Python中文网/ 问答频道 /正文

我尝试过使用相同的给定代码在mnist数据集上使用keras对CNN进行培训和测试。现在,我想在emnist数据集上尝试相同的代码,但会出现以下错误:

我正在尝试以下代码

!!pip安装emnist

import numpy as np
import emnist
from tensorflow import keras

train_images = emnist.train_images()
train_labels = emnist.train_labels()

print(train_images.shape) 
print(train_labels.shape)

以下是输出:

Error:
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-2-812445794c0d> in <module>
      5 # The first time you run this might be a bit slow, since the
      6 # mnist package has to download and cache the data.
----> 7 train_images = emnist.train_images()
      8 train_labels = emnist.train_labels()
      9 

AttributeError: module 'emnist' has no attribute 'train_images' 

请帮忙


Tags: the数据代码importlabelstrainkeras集上
2条回答

如果您查看emnist包的网站https://pypi.org/project/emnist/

您可以看到正确的用法是(例如,使用数字数据集):

from emnist import extract_training_samples
from emnist import extract_test_samples

images, labels = extract_training_samples('digits')
images, labels = extract_test_samples('digits')

没有列车图像方法

您可以在这里查看emnist python包以观察如何正确导入函数:https://pypi.org/project/emnist/

您可以通过导入以下函数来检查它们拥有哪些数据集:

from emnist import list_datasets
list_datasets()

以byclass数据集为例,我们提取样本:

from emnist import extract_training_samples, extract_test_samples
x_train, y_train = extract_training_samples('byclass')
x_test, y_test = extract_test_samples('byclass')

相关问题 更多 >