吴裕雄 python 神经网络——TensorFlow图片预处理
- import numpy as np
- import tensorflow as tf
- import matplotlib.pyplot as plt
- # 使用'r'会出错,无法解码,只能以2进制形式读取
- # img_raw = tf.gfile.FastGFile('E:\\myresource\\moutance.jpg','rb').read()
- img_raw = open('E:\\myresource\\moutance.jpg','rb').read()
- # 把二进制文件解码为uint8
- img_0 = tf.image.decode_png(img_raw)
- # 可以用np直接转换了
- # img_1 = tf.image.convert_image_dtype(img_0,dtype=tf.uint8)
- sess = tf.Session()
- print(sess.run(img_0).shape)
- plt.imshow(sess.run(img_0))
- plt.show()
- def show_pho(img,sess=sess):
- '''
- TF处理过的图片自动转换了类型,需要调整回uint8才能正常显示
- :param sess:
- :param img:
- :return:
- '''
- moutance = np.asarray(sess.run(img),dtype='uint8')
- print(moutance.shape)
- plt.imshow(moutance)
- plt.show()
- '''调整图像大小'''
- # 插值尽量保存原图信息
- img_1 = tf.image.resize_images(img_0,[500,500],method=3)
- show_pho(img_1)
- # 裁剪或填充
- # 自动中央截取
- img_2 = tf.image.resize_image_with_crop_or_pad(img_0,500,500)
- show_pho(img_2)
- # 比例中央裁剪
- img_4 = tf.image.central_crop(img_0,0.5)
- show_pho(img_4)
吴裕雄 python 神经网络——TensorFlow图片预处理的更多相关文章
- 吴裕雄 python 神经网络——TensorFlow图片预处理调整图片
import numpy as np import tensorflow as tf import matplotlib.pyplot as plt def distort_color(image, ...
- 吴裕雄 python 神经网络——TensorFlow 图像预处理完整样例
import numpy as np import tensorflow as tf import matplotlib.pyplot as plt def distort_color(image, ...
- 吴裕雄 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 ...
- 吴裕雄 python 神经网络——TensorFlow 花瓣分类与迁移学习(4)
# -*- coding: utf-8 -*- import glob import os.path import numpy as np import tensorflow as tf from t ...
- 吴裕雄 python 神经网络——TensorFlow 花瓣分类与迁移学习(3)
import glob import os.path import numpy as np import tensorflow as tf from tensorflow.python.platfor ...
- 吴裕雄 python 神经网络——TensorFlow 花瓣分类与迁移学习(2)
import glob import os.path import numpy as np import tensorflow as tf from tensorflow.python.platfor ...
- 吴裕雄 python 神经网络——TensorFlow 花瓣识别2
import glob import os.path import numpy as np import tensorflow as tf from tensorflow.python.platfor ...
随机推荐
- 测度论--长度是怎样炼成的[zz]
http://www.58pic.com/newpic/27882296.html http://www.58pic.com/newpic/27893137.html http://699pic.co ...
- 《NVM-Express-1_4-2019.06.10-Ratified》学习笔记(8.20)-- ANA
8.20 非对称namespace访问报告 8.20.1 非对称namespace访问报告概况 非对称Namespace访问(ANA)在如下场景下产生,基于访问这个namespace的controll ...
- 1054 The Dominant Color
大致题意就是给出N行M列的元素,找出出现次数最多的元素并输出. #include<iostream> #include<unordered_map> using namespa ...
- DTU DeepLearning: exercise 7
torch activation functions: sigmoid, relu, tanh, softplus. https://morvanzhou.github.io/tutorials/ma ...
- XMLHttpRequest: 网络错误 0x2ee4, 由于出现错误 00002ee4 而导致此项操作无法完成
原因: IE11有默认设置安全策略,如果url需要证书,一发送请求IE11就会拒绝,因为ssl certificate(SSL证书) 是非法的 解决方案: (1)修改IE浏览器配置 - 用户使用的电脑 ...
- Python七夕记
- 使用validate进行表单验证时土方法(appendTo)改变error显示的位置
<span style="font-family: Arial, Helvetica, sans-serif; background-color: rgb(255, 255, 255) ...
- echo -e 实现color output
拓展: cp 简化: c'p -rv /data/project/test {.txt,_bak.txt}
- java Map 迭代key,value 最简洁的方法
import java.util.HashMap; import java.util.Map; public class EntrySets { public static void main(Str ...
- Mybatis学习笔记——输入参数parameterType、Mybatis调用存储过程
输入参数:parameterType(两种取值符号) 1.类型为简单类型 区别: (1) #{可以为任意值} ${vaue}--->标识符只能是value (2) ...