import numpy as np
import tensorflow as tf
import matplotlib.pyplot as plt def distort_color(image, color_ordering=0):
'''
随机调整图片的色彩,定义两种处理顺序。
'''
if color_ordering == 0:
image = tf.image.random_brightness(image, max_delta=32./255.)
image = tf.image.random_saturation(image, lower=0.5, upper=1.5)
image = tf.image.random_hue(image, max_delta=0.2)
image = tf.image.random_contrast(image, lower=0.5, upper=1.5)
else:
image = tf.image.random_saturation(image, lower=0.5, upper=1.5)
image = tf.image.random_brightness(image, max_delta=32./255.)
image = tf.image.random_contrast(image, lower=0.5, upper=1.5)
image = tf.image.random_hue(image, max_delta=0.2) return tf.clip_by_value(image, 0.0, 1.0) def preprocess_for_train(image, height, width, bbox): # 查看是否存在标注框。
if image.dtype != tf.float32:
image = tf.image.convert_image_dtype(image, dtype=tf.float32) # 随机的截取图片中一个块。
bbox_begin, bbox_size, _ = tf.image.sample_distorted_bounding_box(
tf.shape(image), bounding_boxes=bbox)
bbox_begin, bbox_size, _ = tf.image.sample_distorted_bounding_box(
tf.shape(image), bounding_boxes=bbox)
distorted_image = tf.slice(image, bbox_begin, bbox_size) # 将随机截取的图片调整为神经网络输入层的大小。
distorted_image = tf.image.resize_images(distorted_image, [height, width], method=np.random.randint(4))
distorted_image = tf.image.random_flip_left_right(distorted_image)
distorted_image = distort_color(distorted_image, np.random.randint(2))
return distorted_image def pre_main(img,bbox=None):
if bbox is None:
bbox = tf.constant([0.0, 0.0, 1.0, 1.0], dtype=tf.float32, shape=[1, 1, 4])
with tf.gfile.FastGFile(img, "rb") as f:
image_raw_data = f.read()
with tf.Session() as sess:
img_data = tf.image.decode_jpeg(image_raw_data)
for i in range(9):
result = preprocess_for_train(img_data, 299, 299, bbox) plt.imshow(result.eval())
plt.axis('off')
plt.savefig("E:\\myresource\\代号{}".format(i)) pre_main("E:\\myresource\\moutance.jpg",bbox=None)
exit()

吴裕雄 python 神经网络——TensorFlow图片预处理调整图片的更多相关文章

  1. 吴裕雄 python 神经网络——TensorFlow 图像预处理完整样例

    import numpy as np import tensorflow as tf import matplotlib.pyplot as plt def distort_color(image, ...

  2. 吴裕雄 python 神经网络——TensorFlow 花瓣分类与迁移学习(2)

    import glob import os.path import numpy as np import tensorflow as tf from tensorflow.python.platfor ...

  3. 吴裕雄 python 神经网络——TensorFlow 图像处理函数

    import numpy as np import tensorflow as tf import matplotlib.pyplot as plt image_raw_data = tf.gfile ...

  4. 吴裕雄 python 神经网络——TensorFlow 花瓣分类与迁移学习(1)

    import glob import os.path import numpy as np import tensorflow as tf from tensorflow.python.platfor ...

  5. 吴裕雄 python 神经网络——TensorFlow训练神经网络:花瓣识别

    import os import glob import os.path import numpy as np import tensorflow as tf from tensorflow.pyth ...

  6. 吴裕雄 python 神经网络——TensorFlow图片预处理

    import numpy as np import tensorflow as tf import matplotlib.pyplot as plt # 使用'r'会出错,无法解码,只能以2进制形式读 ...

  7. 吴裕雄 python 神经网络——TensorFlow 卷积神经网络水果图片识别

    #-*- coding:utf- -*- import time import keras import skimage import numpy as np import tensorflow as ...

  8. 吴裕雄 python 神经网络——TensorFlow 卷积神经网络手写数字图片识别

    import os import tensorflow as tf from tensorflow.examples.tutorials.mnist import input_data INPUT_N ...

  9. 吴裕雄 python 神经网络——TensorFlow 数据集高层操作

    import tempfile import tensorflow as tf train_files = tf.train.match_filenames_once("E:\\output ...

随机推荐

  1. D0 设计模式

    单一职责 一个类只负责一个功能领域中的相应职责.,就一个类而言,应该只有一个引起它变化的原因. 单一职责原则告诉我们: 一个类不能太"累"! 在软件系统中, 一个类( 大到模块, ...

  2. XMLHttpRequest: 网络错误 0x2ee4, 由于出现错误 00002ee4 而导致此项操作无法完成

    原因: IE11有默认设置安全策略,如果url需要证书,一发送请求IE11就会拒绝,因为ssl certificate(SSL证书) 是非法的 解决方案: (1)修改IE浏览器配置 - 用户使用的电脑 ...

  3. 使用tableExport.js直接导出web页面上的table

    1,需要导入两个js文件,一个tableExport.js,另一个是jquery.base64.js,前一个文件是导出数据和核心类库,后一个是为了避免导出中文时乱码的js文件,如果你导出的数据没有中文 ...

  4. Css3 里的弹性盒的比例关系

    前两天朋友出去面试遇到了尴尬的问题,原题是:"在一个盒子里包裹着三个子元素,让子元素的宽度以1:1.1:2.1:3的关系依次展示" 这就尴尬了啊.................. ...

  5. 滑动窗口-洛谷T1866(单调队列)

    咕咕咕 单调队列板子题 一.基本 1.单调队列: 特殊的双端队列,内部元素.分为最大队列(单调递增)和最小队列(单调递减)两种 二.应用 本题中:大部分单调队列优化的动态规划问题都和定长连续子区间的最 ...

  6. 1.5 面试问题整理:cl

    1.自我介绍2.介绍测试的项目> 期望答案:让你介绍项目,目的是想知道你参与过该项目后,对该项目的认识程度和认识层次,从而判断你在项目中到底起多大作用. 即:测试的流程.用例设计的方法.在项目中 ...

  7. numpy特性

    numpy特性 待办 可获取最小值最大值或者排序等操作的索引,然后通过索引取得对应值或者对应值的序列 按行按列求和.按行按列求积 方差等等统计函数使用 enter description here e ...

  8. 【资源分享】CS起源 V34.4044(经典版本)

    *----------------------------------------------[下载区]----------------------------------------------* ...

  9. [转]Vue 2.0——渐进式前端解决方案

    前言:框架是什么?为什么要有框架?在众多的框架之中,Vue 独具魅力之处在哪里呢?其背后的核心思想是什么?Vue 究竟火到什么程度?最近发布的 Vue2.0 又做了哪些改进呢?Vue 和 Weex 又 ...

  10. linux系统下如何打开端口

    1)vi /etc/sysconfig/iptables 2)-A INPUT -m state --state NEW -m tcp -p tcp --dport xxxxxxxxxx -j ACC ...