tensorflow-2.0 技巧 | ImageNet 归一化

_MEAN_RGB = [123.15, 115.90, 103.06]
def _preprocess_subtract_imagenet_mean(inputs):
    """Subtract Imagenet mean RGB value."""
    mean_rgb = tf.reshape(_MEAN_RGB, [1, 1, 1, 3])
    print("mean_rgb:\n", mean_rgb)
    return inputs - mean_rgb
inputs = tf.random.uniform(shape=[2, 448, 448, 3], maxval=255)
print("inputs:\n", inputs)
imgs_new = _preprocess_subtract_imagenet_mean(inputs)
print("imgs_sub:\n", imgs_new)


会Boardcast!
– 从最后面的维度开始匹配。
– 在前面插入若干维度。
– 将维度的size从1通过expand变到和某个Tensor相同的维度。

总之,Broadcasting操作就是自动实现了若干unsqueeze和expand操作,以使两个tensor的shape一致,从而完成某些操作(往往是加法)。

原文地址:https://www.cnblogs.com/ManWingloeng/p/11650784.html

时间: 2024-08-30 17:50:53

tensorflow-2.0 技巧 | ImageNet 归一化的相关文章

tensorflow 1.0 学习:用CNN进行图像分类

tensorflow升级到1.0之后,增加了一些高级模块: 如tf.layers, tf.metrics, 和tf.losses,使得代码稍微有些简化. 任务:花卉分类 版本:tensorflow 1.0 数据:http://download.tensorflow.org/example_images/flower_photos.tgz 花总共有五类,分别放在5个文件夹下. 闲话不多说,直接上代码,希望大家能看懂:) # -*- coding: utf-8 -*- from skimage im

『TensorFlow』0.x_&_1.x版本框架改动汇总

基本数值运算 除法和模运算符(/,//,%)现在匹配 Python(flooring)语义.这也适用于 [tf.div] 和 [tf.mod].要获取基于强制整数截断的行为,可以使用 [tf.truncatediv] 和 [tf.truncatemod]. 现在推荐使用 [tf.divide()] 作为除法函数.[tf.div()] 将保留,但它的语义不会回应 Python 3 或 [from future] 机制 [tf.mul,tf.sub ] 和 [tf.neg] 不再使用,改为 [tf.

TensorFlow 2.0 新特性

安装 TensorFlow 2.0 Alpha 本文仅仅介绍 Windows 的安装方式: pip install tensorflow==2.0.0-alpha0 # cpu 版本 pip install tensorflow==2.0.0-alpha0 # gpu 版本 针对 GPU 版的安装完毕后还需要设置环境变量: SET PATH=C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.0\bin;%PATH% SET PATH=C

【深度学习与TensorFlow 2.0】卷积神经网络(CNN)

注:在很长一段时间,MNIST数据集都是机器学习界很多分类算法的benchmark.初学深度学习,在这个数据集上训练一个有效的卷积神经网络就相当于学习编程的时候打印出一行“Hello World!”.下面基于与MNIST数据集非常类似的另一个数据集Fashion-MNIST数据集来构建一个卷积神经网络. 0. Fashion-MNIST数据集 MNIST数据集在机器学习算法中被广泛使用,下面这句话能概况其重要性和地位: In fact, MNIST is often the first data

Keras 2.3.0 发布:支持TensorFlow 2.0

导读 昨天,Keras团队宣布发布Keras 2.3.0,这是第一个支持TensorFlow 2.0的多后端Keras版本.这也是多后端Keras的最后一个主要版本.它与TensorFlow 1.14,1.13,Theano和CNTK向后兼容. Keras主要关注tf.keras,同时继续支持Theano/CNTK 此版本附带了许多API更改,以使多后端Keras API与TensorFlow的高级API tf.keras“同步”.但是,有些TensorFlow 2.0功能不受支持.这就是团队建

Keras 2.3.0 发布:支持TensorFlow 2.0!!!!!

Keras主要关注tf.keras,同时继续支持Theano/CNTK 此版本附带了许多API更改,以使多后端Keras API与TensorFlow的高级API tf.keras“同步”.但是,有些TensorFlow 2.0功能不受支持.这就是团队建议开发人员在TensorFlow 2.0中将他们的Keras代码切换到tf.keras的原因. 迁移到tf.keras将使开发人员能够访问诸如快速执行,TPU培训以及低级TensorFlow与Layer和Model等高级概念之间更好的集成. 在此

安装Tensorflow 2.0后的坑has no attribute ‘contrib‘

AttributeError: module 'tensorflow' has no attribute 'contrib' The TensorFlow contrib module will not be included in TensorFlow 2.0.For more information, please see: https://github.com/tensorflow/community/blob/master/rfcs/20180907-contrib-sunset.md

升级到Tensorflow 2.0 踩坑

https://blog.csdn.net/javastart/article/details/102525102 Tensorflow 2.0发布已经有一段时间了,各种基于新API的教程看上去的确简单易用,一个简单的mnist手写识别只需要下面不到20行代码就OK了, ? ? import tensorflow as tf mnist = tf.keras.datasets.mnist (x_train, y_train),(x_test, y_test) = mnist.load_data(

tensorflow 1.0 学习:用别人训练好的模型来进行图像分类

谷歌在大型图像数据库ImageNet上训练好了一个Inception-v3模型,这个模型我们可以直接用来进来图像分类. 下载地址:https://storage.googleapis.com/download.tensorflow.org/models/inception_dec_2015.zip 下载完解压后,得到几个文件: 其中的classify_image_graph_def.pb 文件就是训练好的Inception-v3模型. imagenet_synset_to_human_label