TensorFlow 实战(五)—— 图像预处理
2024-08-27 19:47:12
当然 tensorflow 并不是一种用于图像处理的框架,这里图像处理仅仅是一些简单的像素级操作,最终目的比如用于数据增强;
- tf.random_crop()
- tf.image.random_flip_left_right():
- tf.image.random_hue()
- random_contrast()
- random_brightness()
- random_saturation()
def pre_process_image(image, training):
# This function takes a single image as input,
# and a boolean whether to build the training or testing graph.
if training:
# For training, add the following to the TensorFlow graph.
# Randomly crop the input image.
image = tf.random_crop(image, size=[img_size_cropped, img_size_cropped, num_channels])
# Randomly flip the image horizontally.
image = tf.image.random_flip_left_right(image)
# Randomly adjust hue, contrast and saturation.
image = tf.image.random_hue(image, max_delta=0.05)
image = tf.image.random_contrast(image, lower=0.3, upper=1.0)
image = tf.image.random_brightness(image, max_delta=0.2)
image = tf.image.random_saturation(image, lower=0.0, upper=2.0)
# Some of these functions may overflow and result in pixel
# values beyond the [0, 1] range. It is unclear from the
# documentation of TensorFlow 0.10.0rc0 whether this is
# intended. A simple solution is to limit the range.
# Limit the image pixels between [0, 1] in case of overflow.
image = tf.minimum(image, 1.0)
image = tf.maximum(image, 0.0)
else:
# For training, add the following to the TensorFlow graph.
# Crop the input image around the centre so it is the same
# size as images that are randomly cropped during training.
image = tf.image.resize_image_with_crop_or_pad(image,
target_height=img_size_cropped,
target_width=img_size_cropped)
return image
最新文章
- 自定义TextField清除按钮
- 翻译-使用Spring WebService生成SOAP Web Service
- VI打开和编辑多个文件的命令 分屏操作
- Raising Modulo Numbers_快速幂取模算法
- Nagios:企业级系统监控方案
- 11gr2 alert日志中报TNS-12535 TNS-00505原因及解决方法 (转载)
- 导出含有图片的项目成jar文件后运行,图片不显示
- ubuntu 设置显示器的亮度
- [转载]大道至简!!!从SAP HANA作为SAP加速器的方式,看ERP on HANA的春天
- 应用SVN(CentOS中搭建SVN服务器)
- [转] iOS开发- UICollectionView详解+实例
- JNI与JNA性能比较
- Linux 下mysql修改数据库存放目录方法和可能遇到的问题
- BigData-‘基于代价优化’究竟是怎么一回事?
- Go基础系列:Go slice详解
- Emacs 中使用 shell
- C# Web开发中弹出对话框的函数[转载]
- SPOJ 839 Optimal Marks(最小割的应用)
- servlet/和/*匹配的区别
- phpstorm破解方法
热门文章
- 11G、12C Data Guard Physical Standby Switchover转换参考手册
- 软件——protel 的pcb电路图制作
- SQLite基础学习
- Android 关于java.util.NoSuchElementException错误
- [React Intl] Render Content Based on a Number using react-intl FormattedMessage (plural)
- Qt开发程序在Windows 10应用须要管理员执行的解决思路
- 内存问题检查利器——Purify
- SVGALib
- UVA 11624 - Fire! 图BFS
- JScript使用正则表达式的经验