吴裕雄 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 ...
随机推荐
- 题解【AcWing274】移动服务
题面 非常好的优化 \(\text{DP}\) 状态表示的题目. 首先可以设 \(dp_{i,x,y,z}\) 表示已经做完了前 \(i\) 个请求,现在的 \(3\) 名服务员分别在 \(x\) . ...
- 题解【洛谷P1886】滑动窗口 /【模板】单调队列
题面 单调队列模板题. 单调队列可以从队首和队尾出队. 队列中的元素大小具有一定的顺序. 具体可参考这一篇题解 #include <bits/stdc++.h> #define itn i ...
- JavaScript对象之属性操作
在js对象中,我们可以对对象属性进行操作. 上图的要点为:for-in会把原型链上的可枚举属性也列出来. 上图的要点为:可以使用逻辑运算符&&进行层层查找对象是否为undefined, ...
- Python 实现深度学习
前言 最近由于疫情被困在家,于是准备每天看点专业知识,准备写成博客,不定期发布. 博客大概会写5~7篇,主要是"解剖"一些深度学习的底层技术.关于深度学习,计算机专业的人多少都会了 ...
- python面试的100题(2)
def print_directory_contents(sPath): """ 这个函数接收文件夹的名称作为输入参数 返回该文件夹中文件的路径 以及其包含文件夹中文件的 ...
- python:函数中的*args与**kwargs
首先定义一个包含*args和**kwargs的函数,这个函数唯一的功能就是输出自己的两个参数,以此来理解*args和**kwargs def myFunc(*args, **kwargs): prin ...
- optm.adam
optm.adam 待办 https://www.cnblogs.com/dylancao/p/9878978.html 这个优化包 理解求导过程,来理解神经网络.
- 1.3、WebRTC架构
文章导读:本文的讲解的是webrtc系统架构,每个人都要Get到这些知识:第一.了解webrtc架构分层:第二.对每层技术有一个清晰的认知.学完本节内容可以为我们后面学习核心API起到至关重要的作用, ...
- PHP SDK+Oss 上传文件流
// Endpoint以杭州为例,其它Region请按实际情况填写. $endpoint = "http://oss-cn-hangzhou.aliyuncs.com"; // 云 ...
- 为什么CSS,JS以及图片等这些资源的路径需要加问号
我们平时练习的时候,很少写路径上面需要加问号的,而实际应用当中,我们经常看到一些资源的路径后面跟着问号,这是为什么呢? 答:答案很简单哦,其实就是为了防止缓存,我们可以在原本路径的后面加上问号,加上我 ...