吴裕雄 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 ...
随机推荐
- 【Python】简单计算器
#python 3.7.1 print("operation codes are:") print("1 for multiply") print(" ...
- C语言-防止输入字母
今天群里一位小伙伴问了一个关于scanf函数的问题: scanf("%d", &n); 这个代码怎么防止输入字母? 因为他下面是判断n是否为质数,所以这里肯定有个判断,不然 ...
- (转)eclipse调试java程序的九个技巧
转自:http://www.cnblogs.com/lingiu/p/3802391.html 九个技巧: 逻辑结构 条件debug 异常断点 单步过滤 跳到帧 Inspect expressions ...
- 空指针和NULL
#include <stdio.h> int add(int a, int b ){ //函数的返回值和参数意一样有副本机制,存储在寄存器中,而不在内存中,函数的返回值不能取地址 & ...
- Mac升级后如何查看自己的网络端口
OS X 10.9 下面 网络实用工具 从实用工具目录里消失了,可能这个程序用的人太少就取消了吧.但是对于做互联网的人还是有点用的. 参考http://www.mamicode.com/info-de ...
- php设计模式之单例实例代码
<?php header("Content-type:text/html;charset=utf-8"); /** * 第一步,分别实例化 */ /*class Single ...
- Java 浮点数精度控制
1.String.format(String format,Object… args) Java中用String.format()来控制输出精度, format参数用来设置精度格式, args参数代 ...
- AWD - IDE For Web dev汉化版
一款安卓上的HTML网页编辑软件,不错哦 下载链接 http://t.cn/AiRIvtoL
- 5G手机来了,但这些问题让其短期内难以成为“香饽饽”
在5G手机喊了太长时间后,其终于在近日不断亮相. 此前据中国质量认证中心官网显示,共有8款5G手机获得3C认证--华为4款,一加.中兴.OPPO和vivo各有一款.随着首批5G手机通过3C认证,意味着 ...
- Bootstrap入门(1)简介
作者:赵盼盼 出处:https://www.cnblogs.com/zhaopanpan/ Bootstrap是Twitter开源的基于HTML.CSS.JavaScript的前端框架. 它是为实现快 ...