吴裕雄 python 神经网络——TensorFlow图片预处理调整图片
- 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图片预处理调整图片的更多相关文章
- 吴裕雄 python 神经网络——TensorFlow 图像预处理完整样例
import numpy as np import tensorflow as tf import matplotlib.pyplot as plt def distort_color(image, ...
- 吴裕雄 python 神经网络——TensorFlow 花瓣分类与迁移学习(2)
import glob import os.path import numpy as np import tensorflow as tf from tensorflow.python.platfor ...
- 吴裕雄 python 神经网络——TensorFlow 图像处理函数
import numpy as np import tensorflow as tf import matplotlib.pyplot as plt image_raw_data = tf.gfile ...
- 吴裕雄 python 神经网络——TensorFlow 花瓣分类与迁移学习(1)
import glob import os.path import numpy as np import tensorflow as tf from tensorflow.python.platfor ...
- 吴裕雄 python 神经网络——TensorFlow训练神经网络:花瓣识别
import os import glob import os.path import numpy as np import tensorflow as tf from tensorflow.pyth ...
- 吴裕雄 python 神经网络——TensorFlow图片预处理
import numpy as np import tensorflow as tf import matplotlib.pyplot as plt # 使用'r'会出错,无法解码,只能以2进制形式读 ...
- 吴裕雄 python 神经网络——TensorFlow 卷积神经网络水果图片识别
#-*- coding:utf- -*- import time import keras import skimage import numpy as np import tensorflow as ...
- 吴裕雄 python 神经网络——TensorFlow 卷积神经网络手写数字图片识别
import os import tensorflow as tf from tensorflow.examples.tutorials.mnist import input_data INPUT_N ...
- 吴裕雄 python 神经网络——TensorFlow 数据集高层操作
import tempfile import tensorflow as tf train_files = tf.train.match_filenames_once("E:\\output ...
随机推荐
- Execl导入系统
文件导入功能 前台代码: Content\JS\jquery.ajaxfileupload.js<script src="~/Content/JS/jquery.ajaxfileupl ...
- Unity 坐标系转换
在Unity中我们通常会用到以下几个坐标系下的点: 世界坐标系:World Space 简单来讲,我们通过 transform.position | transform.rotation 获取得到的位 ...
- C#设置一个控件可以鼠标拖动
C#设置一个控件可以鼠标拖动: 新建一个C#项目, 创建一个label控件, 设置label的鼠标按下和抬起事件分别为:label1_MouseDown和label1_MouseUp. 对代码进行如下 ...
- 阿里云MySQL安装到centos,并链接。
Last login: Wed Jan 22 11:21:17 on ttys001 wulaguixiaomianyangdeMacBook-Pro:~ xingwen$ ssh root@47.9 ...
- Python中的模块简单认识
将自己定义的方法,变量存放在文件中,为一些脚本或者交互式的解释器实例使用,这个文件称为模块. 细说的话,模块可以分为四个通用类别: 1 使用python编写的.py文件(自定义模块) 2 已被编译为共 ...
- Java中boolean类型到底占用多少字节(转载)
来源:https://www.cnblogs.com/brucecloud/p/5509921.html 虽然 Java 虚拟机定义了 boolean 这种数据类型,但是只对它提供了非常有限的支持.在 ...
- Call to undefined function Illuminate\Encryption\openssl_cipher_iv_length()
今天遇到一个错误,没有定义一个openssl_cipher_iv_length()方法,可是我明明开启OpenSSL了啊 如果开启了还报错 只需要把php的目录加入环境变量 -重启电脑 就解决了 但 ...
- fileupload插件调用upload.parseRequest(request)解析得到空值问题
得到的list长度是0,项目配置不能改变,没办法了,只能将HttpServletRequest强换成DefaultMultipartHttpServletRequest ,直接获取表单中的字段了.方法 ...
- codeforces E. The Contest(最长上升子序列)
题目链接:https://codeforces.com/contest/1257/problem/E 题意:给三个序列k1,k2,k3,每个序列有一堆数,k1是前缀,k3是后缀,k2是中间,现可以从任 ...
- pycharm开发flask指定ip、端口无效
原因分析 是因为使用了pycharm的版本的问题.并不是flask框架本身的问题(不管你是如何设置的flask配置,通过加载config也好,还是通过run的时候传入形参也好,均不影响) 可以很明显的 ...