资源简介
模仿mnist数据集制作自己的数据集,并读取自己的数据集
代码片段和文件信息
# Copyright 2016 The TensorFlow Authors. All Rights Reserved.
#
# Licensed under the Apache License Version 2.0 (the “License“);
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing software
# distributed under the License is distributed on an “AS IS“ BASIS
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================
“““Functions for downloading and reading MNIST data.“““
#-*-coding:utf-8-*-
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import gzip
import numpy
from six.moves import xrange # pylint: disable=redefined-builtin
from tensorflow.contrib.learn.python.learn.datasets import base
from tensorflow.python.framework import dtypes
SOURCE_URL = ‘http://yann.lecun.com/exdb/mnist/‘
def _read32(bytestream):
dt = numpy.dtype(numpy.uint32).newbyteorder(‘>‘)
return numpy.frombuffer(bytestream.read(4) dtype=dt)[0]
def extract_images(f):
“““Extract the images into a 4D uint8 numpy array [index y x depth].
Args:
f: A file object that can be passed into a gzip reader.
Returns:
data: A 4D uint8 numpy array [index y x depth].
Raises:
ValueError: If the bytestream does not start with 2051.
“““
print(‘Extracting‘ f.name)
with gzip.GzipFile(fileobj=f) as bytestream:
magic = _read32(bytestream)
if magic != 2051:
raise ValueError(‘Invalid magic number %d in MNIST image file: %s‘ %
(magic f.name))
num_images = _read32(bytestream)
rows = _read32(bytestream)
cols = _read32(bytestream)
buf = bytestream.read(rows * cols * num_images)
data = numpy.frombuffer(buf dtype=numpy.uint8)
data = data.reshape(num_images rows cols 1)
return data
def dense_to_one_hot(labels_dense num_classes):
“““Convert class labels from scalars to one-hot vectors.“““
num_labels = labels_dense.shape[0]
index_offset = numpy.arange(num_labels) * num_classes
labels_one_hot = numpy.zeros((num_labels num_classes))
labels_one_hot.flat[index_offset + labels_dense.ravel()] = 1
return labels_one_hot
def extract_labels(f one_hot=False num_classes=2): #这里打num_classes手动设置为自己的类别数
“““Extract the labels into a 1D uint8 numpy array [index].
Args:
f: A file object that can be passed into a gzip reader.
one_hot: Does one hot encoding for the result.
num_classes: Number of classes for the one hot encoding.
Returns:
labels: a 1D uint8 numpy array.
Raises:
ValueError: If the bystream doesn‘t start with 2049.
“““
print(‘Extracting‘ f.name)
with gzip.GzipFile(fileobj=f) as bytestream:
magic = _read
相关资源
- 人工智能算法实现mnist手写数字识别
- 利用CNN网络实现mnist图像分类,手动实
- MNIST手写体数字训练/测试数据集(图
- bayes分类python
- knn算法识别mnist图片-python3
- Ubuntu18.04LTS下安装 Caffe-GPU版本及 Ana
- mnist手写数字识别数据集npz文件.zip
- 基于Python的手写字体识别系统
- Python学习实践-sklearn分类算法实践-M
- pytorch版本手写体识别MNIST.zip
- 自己编写的MNIST手写字Python实现
- mnist手写字体识别之BP.zip
- tensorflow操作mnist数据集源代码
- 使用knn对MNIST分类
- tensorflow手写数字识别完整版.zip
- 基于tensorflow的手写体识别python源码附
- 逻辑回归python代码
- mnist手写字体识别之随机森林.zip
- win10+anaconda3+python3 mnist训练代码
- 代码:Python+TensorFlow+PyQt实现手写体数
- SVM分类手动鼠标手写数字-python版本
- 使用python搭建mnist全连接神经网络
- knn_search.py
- Tensorflow实现GAN生成mnist手写数字图片
- 纯python实现mnist手写体识别.zip
- mnist_normal
- 基于selective_search对手写数字串进行分
- 深度学习入门代码 5-1 mnist数据集.p
- tensorflow2.0实现mnist手写数字识别代码
- VGG16实现MNIST数据集识别任务.py
评论
共有 条评论