tensorflow样例代码分析cifar10

李潇然 李潇然     2022-08-28     354

关键词:

git地址:https://github.com/tensorflow/models.git
"""
Routine for decoding the CIFAR-10 binary file format.""" from __future__ import absolute_import from __future__ import division from __future__ import print_function import os from six.moves import xrange # pylint: disable=redefined-builtin import tensorflow as tf # 定义图片的像素,原生图片32 x 32 # Process images of this size. Note that this differs from the original CIFAR # image size of 32 x 32. If one alters this number, then the entire model # architecture will change and any model would need to be retrained. #IMAGE_SIZE = 24 IMAGE_SIZE = 32 # Global constants describing the CIFAR-10 data set. #分类数量 NUM_CLASSES = 10 #训练集大小 NUM_EXAMPLES_PER_EPOCH_FOR_TRAIN = 50000 #评价集大小 NUM_EXAMPLES_PER_EPOCH_FOR_EVAL = 10000 #从CIFAR10数据文件中读取样例 #filename_queue一个队列的文件名 def read_cifar10(filename_queue): """ Reads and parses examples from CIFAR10 data files. Recommendation: if you want N-way read parallelism, call this function N times. This will give you N independent Readers reading different files & positions within those files, which will give better mixing of examples. Args: filename_queue: A queue of strings with the filenames to read from. Returns: An object representing a single example, with the following fields: height: number of rows in the result (32) width: number of columns in the result (32) depth: number of color channels in the result (3) key: a scalar string Tensor describing the filename & record number for this example. label: an int32 Tensor with the label in the range 0..9. uint8image: a [height, width, depth] uint8 Tensor with the image data """ class CIFAR10Record(object): pass result = CIFAR10Record() # Dimensions of the images in the CIFAR-10 dataset. # See http://www.cs.toronto.edu/~kriz/cifar.html for a description of the # input format. #分类结果的长度,CIFAR-100长度为2 label_bytes = 1 # 2 for CIFAR-100 result.height = 32 result.width = 32 #3位表示rgb颜色(0-255,0-255,0-255) result.depth = 3 image_bytes = result.height * result.width * result.depth # Every record consists of a label followed by the image, with a # fixed number of bytes for each. #单个记录的总长度=分类结果长度+图片长度 record_bytes = label_bytes + image_bytes # Read a record, getting filenames from the filename_queue. No # header or footer in the CIFAR-10 format, so we leave header_bytes # and footer_bytes at their default of 0. reader = tf.FixedLengthRecordReader(record_bytes=record_bytes) result.key, value = reader.read(filename_queue) # Convert from a string to a vector of uint8 that is record_bytes long. record_bytes = tf.decode_raw(value, tf.uint8) # 第一位代表lable-图片的正确分类结果,从uint8转换为int32类型 # The first bytes represent the label, which we convert from uint8->int32. result.label = tf.cast( tf.strided_slice(record_bytes, [0], [label_bytes]), tf.int32) # 分类结果之后的数据代表图片,我们重新调整大小 # The remaining bytes after the label represent the image, which we reshape # from [depth * height * width] to [depth, height, width]. depth_major = tf.reshape( tf.strided_slice(record_bytes, [label_bytes], [label_bytes + image_bytes]), [result.depth, result.height, result.width]) # 格式转换,从[颜色,高度,宽度]--》[高度,宽度,颜色] # Convert from [depth, height, width] to [height, width, depth]. result.uint8image = tf.transpose(depth_major, [1, 2, 0]) return result #构建一个排列后的一组图片和分类 def _generate_image_and_label_batch(image, label, min_queue_examples, batch_size, shuffle): """Construct a queued batch of images and labels. Args: image: 3-D Tensor of [height, width, 3] of type.float32. label: 1-D Tensor of type.int32 min_queue_examples: int32, minimum number of samples to retain in the queue that provides of batches of examples. batch_size: Number of images per batch. shuffle: boolean indicating whether to use a shuffling queue. Returns: images: Images. 4D tensor of [batch_size, height, width, 3] size. labels: Labels. 1D tensor of [batch_size] size. """ # Create a queue that shuffles the examples, and then # read ‘batch_size‘ images + labels from the example queue. # 线程数 num_preprocess_threads = 8 if shuffle: images, label_batch = tf.train.shuffle_batch( [image, label], batch_size=batch_size, num_threads=num_preprocess_threads, capacity=min_queue_examples + 3 * batch_size, min_after_dequeue=min_queue_examples) else: images, label_batch = tf.train.batch( [image, label], batch_size=batch_size, num_threads=num_preprocess_threads, capacity=min_queue_examples + 3 * batch_size) # Display the training images in the visualizer. tf.summary.image(images, images) return images, tf.reshape(label_batch, [batch_size]) #构建变换输入 def distorted_inputs(data_dir, batch_size): """Construct distorted input for CIFAR training using the Reader ops. Args: data_dir: Path to the CIFAR-10 data directory. batch_size: Number of images per batch. Returns: images: Images. 4D tensor of [batch_size, IMAGE_SIZE, IMAGE_SIZE, 3] size. labels: Labels. 1D tensor of [batch_size] size. """ filenames = [os.path.join(data_dir, data_batch_%d.bin % i) for i in xrange(1, 6)] for f in filenames: if not tf.gfile.Exists(f): raise ValueError(Failed to find file: + f) # Create a queue that produces the filenames to read. filename_queue = tf.train.string_input_producer(filenames) # Read examples from files in the filename queue. read_input = read_cifar10(filename_queue) reshaped_image = tf.cast(read_input.uint8image, tf.float32) height = IMAGE_SIZE width = IMAGE_SIZE # Image processing for training the network. Note the many random # distortions applied to the image. # 随机裁剪图片 # Randomly crop a [height, width] section of the image. distorted_image = tf.random_crop(reshaped_image, [height, width, 3]) # 随机旋转图片 # Randomly flip the image horizontally. distorted_image = tf.image.random_flip_left_right(distorted_image) # Because these operations are not commutative, consider randomizing # the order their operation. # 亮度变换 distorted_image = tf.image.random_brightness(distorted_image, max_delta=63) #对比度变换 distorted_image = tf.image.random_contrast(distorted_image, lower=0.2, upper=1.8) # Subtract off the mean and divide by the variance of the pixels. # Linearly scales image to have zero mean and unit norm # 标准化 float_image = tf.image.per_image_standardization(distorted_image) # Set the shapes of tensors. float_image.set_shape([height, width, 3]) read_input.label.set_shape([1]) # Ensure that the random shuffling has good mixing properties. min_fraction_of_examples_in_queue = 0.4 min_queue_examples = int(NUM_EXAMPLES_PER_EPOCH_FOR_TRAIN * min_fraction_of_examples_in_queue) print (Filling queue with %d CIFAR images before starting to train. This will take a few minutes. % min_queue_examples) # Generate a batch of images and labels by building up a queue of examples. return _generate_image_and_label_batch(float_image, read_input.label, min_queue_examples, batch_size, shuffle=True) # 为CIFAR评价构建输入 # eval_data使用训练还是评价数据集 # data_dir路径 # batch_size一个组的大小 def inputs(eval_data, data_dir, batch_size): """Construct input for CIFAR evaluation using the Reader ops. Args: eval_data: bool, indicating if one should use the train or eval data set. data_dir: Path to the CIFAR-10 data directory. batch_size: Number of images per batch. Returns: images: Images. 4D tensor of [batch_size, IMAGE_SIZE, IMAGE_SIZE, 3] size. labels: Labels. 1D tensor of [batch_size] size. """ if not eval_data: filenames = [os.path.join(data_dir, data_batch_%d.bin % i) for i in xrange(1, 6)] num_examples_per_epoch = NUM_EXAMPLES_PER_EPOCH_FOR_TRAIN else: filenames = [os.path.join(data_dir, test_batch.bin)] num_examples_per_epoch = NUM_EXAMPLES_PER_EPOCH_FOR_EVAL for f in filenames: if not tf.gfile.Exists(f): raise ValueError(Failed to find file: + f) # Create a queue that produces the filenames to read. filename_queue = tf.train.string_input_producer(filenames) # Read examples from files in the filename queue. read_input = read_cifar10(filename_queue) reshaped_image = tf.cast(read_input.uint8image, tf.float32) height = IMAGE_SIZE width = IMAGE_SIZE # Image processing for evaluation. # Crop the central [height, width] of the image. resized_image = tf.image.resize_image_with_crop_or_pad(reshaped_image, height, width) # Subtract off the mean and divide by the variance of the pixels. float_image = tf.image.per_image_standardization(resized_image) # Set the shapes of tensors. float_image.set_shape([height, width, 3]) read_input.label.set_shape([1]) # Ensure that the random shuffling has good mixing properties. min_fraction_of_examples_in_queue = 0.4 min_queue_examples = int(num_examples_per_epoch * min_fraction_of_examples_in_queue) # Generate a batch of images and labels by building up a queue of examples. return _generate_image_and_label_batch(float_image, read_input.label, min_queue_examples, batch_size, shuffle=False)

 

# Copyright 2015 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.
# ==============================================================================

"""Routine for decoding the CIFAR-10 binary file format."""

from __future__ import absolute_import
from __future__ import division
from __future__ import print_function

import os

from six.moves import xrange # pylint: disable=redefined-builtin
import tensorflow as tf

# 定义图片的像素,原生图片32 x 32
# Process images of this size. Note that this differs from the original CIFAR
# image size of 32 x 32. If one alters this number, then the entire model
# architecture will change and any model would need to be retrained.
#IMAGE_SIZE = 24
IMAGE_SIZE = 32
# Global constants describing the CIFAR-10 data set.
#分类数量
NUM_CLASSES = 10
#训练集大小
NUM_EXAMPLES_PER_EPOCH_FOR_TRAIN = 50000
#评价集大小
NUM_EXAMPLES_PER_EPOCH_FOR_EVAL = 10000

#从CIFAR10数据文件中读取样例
#filename_queue一个队列的文件名
def read_cifar10(filename_queue):
"""
Reads and parses examples from CIFAR10 data files.

Recommendation: if you want N-way read parallelism, call this function
N times. This will give you N independent Readers reading different
files & positions within those files, which will give better mixing of
examples.

Args:
filename_queue: A queue of strings with the filenames to read from.

Returns:
An object representing a single example, with the following fields:
height: number of rows in the result (32)
width: number of columns in the result (32)
depth: number of color channels in the result (3)
key: a scalar string Tensor describing the filename & record number
for this example.
label: an int32 Tensor with the label in the range 0..9.
uint8image: a [height, width, depth] uint8 Tensor with the image data
"""

class CIFAR10Record(object):
pass
result = CIFAR10Record()

# Dimensions of the images in the CIFAR-10 dataset.
# See http://www.cs.toronto.edu/~kriz/cifar.html for a description of the
# input format.
#分类结果的长度,CIFAR-100长度为2
label_bytes = 1 # 2 for CIFAR-100
result.height = 32
result.width = 32
#3位表示rgb颜色(0-255,0-255,0-255)
result.depth = 3
image_bytes = result.height * result.width * result.depth
# Every record consists of a label followed by the image, with a
# fixed number of bytes for each.
#单个记录的总长度=分类结果长度+图片长度
record_bytes = label_bytes + image_bytes

# Read a record, getting filenames from the filename_queue. No
# header or footer in the CIFAR-10 format, so we leave header_bytes
# and footer_bytes at their default of 0.
reader = tf.FixedLengthRecordReader(record_bytes=record_bytes)
result.key, value = reader.read(filename_queue)

# Convert from a string to a vector of uint8 that is record_bytes long.
record_bytes = tf.decode_raw(value, tf.uint8)

# 第一位代表lable-图片的正确分类结果,从uint8转换为int32类型
# The first bytes represent the label, which we convert from uint8->int32.
result.label = tf.cast(
tf.strided_slice(record_bytes, [0], [label_bytes]), tf.int32)

# 分类结果之后的数据代表图片,我们重新调整大小
# The remaining bytes after the label represent the image, which we reshape
# from [depth * height * width] to [depth, height, width].
depth_major = tf.reshape(
tf.strided_slice(record_bytes, [label_bytes],
[label_bytes + image_bytes]),
[result.depth, result.height, result.width])
# 格式转换,从[颜色,高度,宽度]--》[高度,宽度,颜色]
# Convert from [depth, height, width] to [height, width, depth].
result.uint8image = tf.transpose(depth_major, [1, 2, 0])

return result

#构建一个排列后的一组图片和分类
def _generate_image_and_label_batch(image, label, min_queue_examples,
batch_size, shuffle):
"""Construct a queued batch of images and labels.

Args:
image: 3-D Tensor of [height, width, 3] of type.float32.
label: 1-D Tensor of type.int32
min_queue_examples: int32, minimum number of samples to retain
in the queue that provides of batches of examples.
batch_size: Number of images per batch.
shuffle: boolean indicating whether to use a shuffling queue.

Returns:
images: Images. 4D tensor of [batch_size, height, width, 3] size.
labels: Labels. 1D tensor of [batch_size] size.
"""
# Create a queue that shuffles the examples, and then
# read ‘batch_size‘ images + labels from the example queue.
# 线程数
num_preprocess_threads = 8
if shuffle:
images, label_batch = tf.train.shuffle_batch(
[image, label],
batch_size=batch_size,
num_threads=num_preprocess_threads,
capacity=min_queue_examples + 3 * batch_size,
min_after_dequeue=min_queue_examples)
else:
images, label_batch = tf.train.batch(
[image, label],
batch_size=batch_size,
num_threads=num_preprocess_threads,
capacity=min_queue_examples + 3 * batch_size)

# Display the training images in the visualizer.
tf.summary.image(‘images‘, images)

return images, tf.reshape(label_batch, [batch_size])

#构建变换输入
def distorted_inputs(data_dir, batch_size):
"""Construct distorted input for CIFAR training using the Reader ops.

Args:
data_dir: Path to the CIFAR-10 data directory.
batch_size: Number of images per batch.

Returns:
images: Images. 4D tensor of [batch_size, IMAGE_SIZE, IMAGE_SIZE, 3] size.
labels: Labels. 1D tensor of [batch_size] size.
"""
filenames = [os.path.join(data_dir, ‘data_batch_%d.bin‘ % i)
for i in xrange(1, 6)]
for f in filenames:
if not tf.gfile.Exists(f):
raise ValueError(‘Failed to find file: ‘ + f)

# Create a queue that produces the filenames to read.
filename_queue = tf.train.string_input_producer(filenames)

# Read examples from files in the filename queue.
read_input = read_cifar10(filename_queue)
reshaped_image = tf.cast(read_input.uint8image, tf.float32)

height = IMAGE_SIZE
width = IMAGE_SIZE

# Image processing for training the network. Note the many random
# distortions applied to the image.
# 随机裁剪图片
# Randomly crop a [height, width] section of the image.
distorted_image = tf.random_crop(reshaped_image, [height, width, 3])
# 随机旋转图片
# Randomly flip the image horizontally.
distorted_image = tf.image.random_flip_left_right(distorted_image)

# Because these operations are not commutative, consider randomizing
# the order their operation.
# 亮度变换
distorted_image = tf.image.random_brightness(distorted_image,
max_delta=63)
#对比度变换
distorted_image = tf.image.random_contrast(distorted_image,
lower=0.2, upper=1.8)

# Subtract off the mean and divide by the variance of the pixels.
# Linearly scales image to have zero mean and unit norm
# 标准化
float_image = tf.image.per_image_standardization(distorted_image)

# Set the shapes of tensors.
float_image.set_shape([height, width, 3])
read_input.label.set_shape([1])

# Ensure that the random shuffling has good mixing properties.
min_fraction_of_examples_in_queue = 0.4
min_queue_examples = int(NUM_EXAMPLES_PER_EPOCH_FOR_TRAIN *
min_fraction_of_examples_in_queue)
print (‘Filling queue with %d CIFAR images before starting to train. ‘
‘This will take a few minutes.‘ % min_queue_examples)

# Generate a batch of images and labels by building up a queue of examples.
return _generate_image_and_label_batch(float_image, read_input.label,
min_queue_examples, batch_size,
shuffle=True)

# 为CIFAR评价构建输入
# eval_data使用训练还是评价数据集
# data_dir路径
# batch_size一个组的大小
def inputs(eval_data, data_dir, batch_size):
"""Construct input for CIFAR evaluation using the Reader ops.

Args:
eval_data: bool, indicating if one should use the train or eval data set.
data_dir: Path to the CIFAR-10 data directory.
batch_size: Number of images per batch.

Returns:
images: Images. 4D tensor of [batch_size, IMAGE_SIZE, IMAGE_SIZE, 3] size.
labels: Labels. 1D tensor of [batch_size] size.
"""
if not eval_data:
filenames = [os.path.join(data_dir, ‘data_batch_%d.bin‘ % i)
for i in xrange(1, 6)]
num_examples_per_epoch = NUM_EXAMPLES_PER_EPOCH_FOR_TRAIN
else:
filenames = [os.path.join(data_dir, ‘test_batch.bin‘)]
num_examples_per_epoch = NUM_EXAMPLES_PER_EPOCH_FOR_EVAL

for f in filenames:
if not tf.gfile.Exists(f):
raise ValueError(‘Failed to find file: ‘ + f)

# Create a queue that produces the filenames to read.
filename_queue = tf.train.string_input_producer(filenames)

# Read examples from files in the filename queue.
read_input = read_cifar10(filename_queue)
reshaped_image = tf.cast(read_input.uint8image, tf.float32)

height = IMAGE_SIZE
width = IMAGE_SIZE

# Image processing for evaluation.
# Crop the central [height, width] of the image.
resized_image = tf.image.resize_image_with_crop_or_pad(reshaped_image,
height, width)

# Subtract off the mean and divide by the variance of the pixels.
float_image = tf.image.per_image_standardization(resized_image)

# Set the shapes of tensors.
float_image.set_shape([height, width, 3])
read_input.label.set_shape([1])

# Ensure that the random shuffling has good mixing properties.
min_fraction_of_examples_in_queue = 0.4
min_queue_examples = int(num_examples_per_epoch *
min_fraction_of_examples_in_queue)

# Generate a batch of images and labels by building up a queue of examples.
return _generate_image_and_label_batch(float_image, read_input.label,
min_queue_examples, batch_size,
shuffle=False)


使用 tfprof 分析 TensorFlow

】使用tfprof分析TensorFlow【英文标题】:ProfilingTensorFlowusingtfprof【发布时间】:2017-02-1723:33:09【问题描述】:我正在尝试分析TensorFlow的计算/内存使用情况,并发现tfprof是适合我目的的正确工具。但是,我无法获得所有运营商的FLO... 查看详情

深度学习基于tensorflow的小型物体识别训练(数据集:cifar-10)(代码片段)

...集的区别下载数据集官方下载地址(较慢)使用tensorflow下载(推荐)使用迅雷(推荐)采用CPU训练还是GPU训练区别使用CPU训练使用GPU训练显示部分图片建立CNN模型网络结构参数量主函 查看详情

cifar-10图像识别(代码片段)

零、学习目标tensorflow数据读取原理深度学习数据增强原理一、CIFAR-10数据集简介是用于普通物体识别的小型数据集,一共包含10个类别的RGB彩×××片(包含:(飞机、汽车、鸟类、猫、鹿、狗、蛙、马、船、卡车)。图片大小均... 查看详情

tensorflow------tfrecords的读取实例(代码片段)

TensorFlow------TFRecords的读取实例: importosimporttensorflowastf#定义cifar的数据等命令行参数FLAGS=tf.app.flags.FLAGStf.app.flags.DEFINE_string(‘cifar_dir‘,‘./data/cifar10/cifar-10-batches-bin‘,‘文件的目录‘)tf.app.fl 查看详情

Tensorflow:如何使用来自 cifar10 的 tf.train.batch 绘制小批量?

】Tensorflow:如何使用来自cifar10的tf.train.batch绘制小批量?【英文标题】:Tensorflow:howtodrawmini-batchusingtf.train.batchfromcifar10?【发布时间】:2017-08-3010:03:38【问题描述】:我正在尝试从cifar10二进制文件中提取小批量。在实现下面显示... 查看详情

利用tensorflow读取二进制cifar-10数据集

使用Tensorflow读取CIFAR-10二进制数据集觉得有用的话,欢迎一起讨论相互学习~FollowMe参考文献Tensorflow官方文档tf.transpose函数解析tf.slice函数解析CIFAR10/CIFAR100数据集介绍tf.train.shuffle_batch函数解析Pythonurlliburlretrieve函数解析importosimportta... 查看详情

tensorflow机器学习入门——cifar10数据集的读取展示与保存(代码片段)

基本信息官网:http://www.cs.toronto.edu/~kriz/cifar.html共60000张图片:50000张用于训练、10000张用于测试图片大小为:32X32数据集图片分为10类:每类6000张数据集下载解压后的目录结构:读取、打印和保存数据集中指定的图片:importpicklei... 查看详情

tensorflow训练cifar10报错

1、AttributeError:‘module‘objecthasnoattribute‘random_crop‘解决方案:将distorted_image=tf.image.random_crop(reshaped_image,[height,width])改为:distorted_image=tf.random_crop(reshaped_image,[height,width,3])2、A 查看详情

Logistic Regression Cifar10- 使用 tensorflow 1.x 的图像分类

】LogisticRegressionCifar10-使用tensorflow1.x的图像分类【英文标题】:LogisticRegressionCifar10-imageclassificationusingtensorflow1.x【发布时间】:2021-03-1819:31:58【问题描述】:我正在尝试使用Cifar10数据集为图像分类实现简单的逻辑回归。我只被... 查看详情

如何在 Tensorflow 上测试自己的图像到 Cifar-10 教程?

】如何在Tensorflow上测试自己的图像到Cifar-10教程?【英文标题】:HowcanItestownimagetoCifar-10tutorialonTensorflow?【发布时间】:2017-02-1209:38:39【问题描述】:我训练了TensorflowCifar10模型,我想用自己的单张图像(32*32,jpg/png)喂它。我... 查看详情

TensorFlow 多 GPU InvalidArgumentError:cifar10_multi_gpu.py

】TensorFlow多GPUInvalidArgumentError:cifar10_multi_gpu.py【英文标题】:TensorFlowmulti-GPUInvalidArgumentError:cifar10_multi_gpu.py【发布时间】:2018-01-2017:54:10【问题描述】:我尝试使用多GPU训练我的模型。所以我运行cifar10_multi_gpu.py(https://github.com/... 查看详情

再来一个tensorflow的测试性能的代码(代码片段)

感觉这个比前一套,容易理解些~~关于数据提前下载的问题:https://www.jianshu.com/p/5116046733fe如果使用keras的cifar10.load_data()函数,你会发现,代码会自动去下载cifar-10-python.tar.gz文件实际上,通过查看cifar10.py和site-packages/keras/utils/data... 查看详情

tensorflow之cifar-10介绍

参考技术ACIFAR-10是由Alex和Ilya整理的一个用于识别普适物体的小型数据集。一共包括10格类别的RGB彩色图片:飞机、汽车、鸟、猫、鹿、狗、蛙、马、船、卡车图片尺寸为:32*32数据集中:50000张训练图、10000张测试图与MNIST相比,... 查看详情

Tensorflow CIFAR10 教程:确定训练过程中的 epoch 数

】TensorflowCIFAR10教程:确定训练过程中的epoch数【英文标题】:TensorflowCIFAR10Tutorial:Determiningnumberofepochsintrainingprocess【发布时间】:2017-10-2413:06:09【问题描述】:这可能是一个非常基本的问题。我是深度学习的新手,从我收集的数... 查看详情

如何创建类似于 cifar-10 的数据集 [关闭]

...我想创建一个与cifar-10数据集格式相同的数据集,以用于Tensorflow。它应该有图像和标签。我希望能够获取cifar-10代码但不同的图像和标签,并运行该代码。【问题讨论】:【参考方案1】:首先我们需要了解CIFAR1 查看详情

用tensorflow神经网络实现一个简易的图片分类器(代码片段)

文章写的不清晰请大家原谅QAQ  这篇文章我们将用 CIFAR-10数据集做一个很简易的图片分类器。在 CIFAR-10数据集包含了60,000张图片。在此数据集中,有10个不同的类别,每个类别中有6,000个图像。每幅图像的大小为32x32像... 查看详情

tfboys(tensorflowboys)养成记

...乐,再过几天元旦节快乐。来继续学习,在/home/your_name/TensorFlow/cifar10/下新建文件夹cifar10_train,用来保存训练时的日志logs,继续在/home/your_name/TensorFlow/cifar10/cifar10.py中输入如下代码:deftrain():#global_stepglobal_ 查看详情

tensorflow2.0处理图片数据-cifar2分类(代码片段)

...行分类。我们准备的Cifar2数据集的文件结构如下所示。在tensorflow中准备图片数据的常用方案有两种,第一种是使用tf.keras中的ImageDataGenerator工具构建图片数据生成器。第二种是使用tf.data.Dataset搭配tf.image中的一些图片处理方法构... 查看详情