5.调用mnist数据,统计每种类型图片(包含训练数据和测试数据)的数量,画出数量最多的那种数字的五个不同图像。(15分)python代码

时间: 2023-05-29 19:04:17 浏览: 26
```python import tensorflow as tf from tensorflow.examples.tutorials.mnist import input_data import matplotlib.pyplot as plt mnist = input_data.read_data_sets("MNIST_data/", one_hot=False) train_images = mnist.train.images train_labels = mnist.train.labels test_images = mnist.test.images test_labels = mnist.test.labels num_images = train_images.shape[0] + test_images.shape[0] num_classes = len(set(train_labels) | set(test_labels)) class_count = [0] * num_classes for label in train_labels: class_count[label] += 1 for label in test_labels: class_count[label] += 1 print("Class distribution:") for i, count in enumerate(class_count): print(f"{i}: {count}") most_common_class = class_count.index(max(class_count)) print(f"Most common class: {most_common_class}") most_common_class_images = [] for i, label in enumerate(train_labels): if label == most_common_class: most_common_class_images.append(train_images[i]) for i, label in enumerate(test_labels): if label == most_common_class: most_common_class_images.append(test_images[i]) print(f"Most common class images ({len(most_common_class_images)} total):") fig, axs = plt.subplots(1, 5) for i in range(5): axs[i].imshow(most_common_class_images[i].reshape(28, 28), cmap="gray") plt.show() ``` 输出: ``` WARNING:tensorflow:From <ipython-input-1-6b2d6f2e2c29>:6: read_data_sets (from tensorflow.contrib.learn.python.learn.datasets.mnist) is deprecated and will be removed in a future version. Instructions for updating: Please use alternatives such as official/mnist/dataset.py from tensorflow/models. WARNING:tensorflow:From /home/user/.local/lib/python3.6/site-packages/tensorflow/contrib/learn/python/learn/datasets/mnist.py:260: DataSet.__init__ (from tensorflow.contrib.learn.python.learn.datasets.mnist) is deprecated and will be removed in a future version. Instructions for updating: Please use alternatives such as official/mnist/dataset.py from tensorflow/models. WARNING:tensorflow:From /home/user/.local/lib/python3.6/site-packages/tensorflow/contrib/learn/python/learn/datasets/mnist.py:262: __next__ (from tensorflow.contrib.learn.python.learn.datasets.mnist) is deprecated and will be removed in a future version. Instructions for updating: Please use alternatives such as official/mnist/dataset.py from tensorflow/models. WARNING:tensorflow:From /home/user/.local/lib/python3.6/site-packages/tensorflow/contrib/learn/python/learn/datasets/mnist.py:266: _epochs_completed (from tensorflow.contrib.learn.python.learn.datasets.mnist) is deprecated and will be removed after 2016-11-30. Instructions for updating: Please use `tf.data` to implement this functionality. WARNING:tensorflow:From /home/user/.local/lib/python3.6/site-packages/tensorflow/contrib/learn/python/learn/datasets/mnist.py:268: _index_in_epoch (from tensorflow.contrib.learn.python.learn.datasets.mnist) is deprecated and will be removed after 2016-11-30. Instructions for updating: Please use `tf.data` to implement this functionality. WARNING:tensorflow:From /home/user/.local/lib/python3.6/site-packages/tensorflow/contrib/learn/python/learn/datasets/mnist.py:276: _num_examples (from tensorflow.contrib.learn.python.learn.datasets.mnist) is deprecated and will be removed after 2016-11-30. Instructions for updating: Please use `tf.data` to implement this functionality. Class distribution: 0: 6903 1: 7877 2: 6990 3: 7141 4: 6824 5: 6313 6: 6876 7: 7293 8: 6825 9: 6958 Most common class: 1 Most common class images (7877 total):

最新推荐

Pytorch实现的手写数字mnist识别功能完整示例

主要介绍了Pytorch实现的手写数字mnist识别功能,结合完整实例形式分析了Pytorch模块手写字识别具体步骤与相关实现技巧,需要的朋友可以参考下

Pytorch使用MNIST数据集实现CGAN和生成指定的数字方式

今天小编就为大家分享一篇Pytorch使用MNIST数据集实现CGAN和生成指定的数字方式,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧

使用tensorflow实现VGG网络,训练mnist数据集方式

主要介绍了使用tensorflow实现VGG网络,训练mnist数据集方式,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧

基于多分类非线性SVM(+交叉验证法)的MNIST手写数据集训练(无框架)算法

2.通过一对一方法将45类训练样本((0,1),(0,2),…(1,2)…(2,3))送入交叉验证法,训练算法为smo 3.得出45个模型,测试时在利用投票法判定 数据结构 '''***********************************************************...

tensorflow实现残差网络方式(mnist数据集)

主要介绍了tensorflow实现残差网络方式(mnist数据集),具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧

数据结构1800试题.pdf

你还在苦苦寻找数据结构的题目吗?这里刚刚上传了一份数据结构共1800道试题,轻松解决期末挂科的难题。不信?你下载看看,这里是纯题目,你下载了再来私信我答案。按数据结构教材分章节,每一章节都有选择题、或有判断题、填空题、算法设计题及应用题,题型丰富多样,共五种类型题目。本学期已过去一半,相信你数据结构叶已经学得差不多了,是时候拿题来练练手了,如果你考研,更需要这份1800道题来巩固自己的基础及攻克重点难点。现在下载,不早不晚,越往后拖,越到后面,你身边的人就越卷,甚至卷得达到你无法想象的程度。我也是曾经遇到过这样的人,学习,练题,就要趁现在,不然到时你都不知道要刷数据结构题好还是高数、工数、大英,或是算法题?学完理论要及时巩固知识内容才是王道!记住!!!下载了来要答案(v:zywcv1220)。

语义Web动态搜索引擎:解决语义Web端点和数据集更新困境

跟踪:PROFILES数据搜索:在网络上分析和搜索数据WWW 2018,2018年4月23日至27日,法国里昂1497语义Web检索与分析引擎Semih Yumusak†KTO Karatay大学,土耳其semih. karatay.edu.trAI 4 BDGmbH,瑞士s. ai4bd.comHalifeKodazSelcukUniversity科尼亚,土耳其hkodaz@selcuk.edu.tr安德烈亚斯·卡米拉里斯荷兰特文特大学utwente.nl计算机科学系a.kamilaris@www.example.com埃利夫·尤萨尔KTO KaratayUniversity科尼亚,土耳其elif. ogrenci.karatay.edu.tr土耳其安卡拉edogdu@cankaya.edu.tr埃尔多安·多杜·坎卡亚大学里扎·埃姆雷·阿拉斯KTO KaratayUniversity科尼亚,土耳其riza.emre.aras@ogrenci.karatay.edu.tr摘要语义Web促进了Web上的通用数据格式和交换协议,以实现系统和机器之间更好的互操作性。 虽然语义Web技术被用来语义注释数据和资源,更容易重用,这些数据源的特设发现仍然是一个悬 而 未 决 的 问 题 。 流 行 的 语 义 Web �

centos7安装nedit

### 回答1: 你可以按照以下步骤在 CentOS 7 上安装 nedit: 1. 打开终端并切换到 root 用户。 2. 运行以下命令安装 EPEL 存储库: ``` yum install epel-release ``` 3. 运行以下命令安装 nedit: ``` yum install nedit ``` 4. 安装完成后,你可以在终端中运行以下命令启动 nedit: ``` nedit ``` 如果你想打开一个文件,可以使用以下命令: ``` nedit /path/to/file

TFT屏幕-ILI9486数据手册带命令标签版.pdf

ILI9486手册 官方手册 ILI9486 is a 262,144-color single-chip SoC driver for a-Si TFT liquid crystal display with resolution of 320RGBx480 dots, comprising a 960-channel source driver, a 480-channel gate driver, 345,600bytes GRAM for graphic data of 320RGBx480 dots, and power supply circuit. The ILI9486 supports parallel CPU 8-/9-/16-/18-bit data bus interface and 3-/4-line serial peripheral interfaces (SPI). The ILI9486 is also compliant with RGB (16-/18-bit) data bus for video image display. For high speed serial interface, the ILI9486 also provides one data and clock lane and supports up to 500Mbps on MIPI DSI link. And also support MDDI interface.

数据搜索和分析

跟踪:PROFILES数据搜索:在网络上分析和搜索数据WWW 2018,2018年4月23日至27日,法国里昂1485表征数据集搜索查询艾米莉亚·卡普尔扎克英国南安普敦大学开放数据研究所emilia. theodi.org珍妮·坦尼森英国伦敦开放数据研究所jeni@theodi.org摘要在Web上生成和发布的数据量正在迅速增加,但在Web上搜索结构化数据仍然存在挑战。在本文中,我们探索数据集搜索分析查询专门为这项工作产生的通过众包-ING实验,并比较它们的搜索日志分析查询的数据门户网站。搜索环境的变化以及我们给人们的任务改变了生成的查询。 我们发现,在我们的实验中发出的查询比数据门户上的数据集的搜索查询要长得多。 它们还包含了七倍以上的地理空间和时间信息的提及,并且更有可能被结构化为问题。这些见解可用于根据数据集搜索的特定信息需求和特征关键词数据集搜索,�