吴裕雄 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 ...
随机推荐
- [USACO19OPEN]I Would Walk 500 Miles 贪心
题目 洛谷P5425(点击可跳转) 题目描述 Farmer John想要将他的编号为 \(1 \ldots N\)的 N N 头奶牛( \(N \leq 7500\) )分为非空的 \(K\) 组( ...
- [NOI2015] 品酒大会 - 后缀数组,并查集,STL,启发式合并
[NOI2015] 品酒大会 Description 对于每一个 \(i \in [0,n)\) 求有多少对后缀满足 LCP 长度 \(\le i\) ,并求满足条件的两个后缀权值乘积的最大值. So ...
- 服务遇到的问题 Linux
1.vnc配置: https://www.cnblogs.com/leolzi/p/9907856.html 2.遇到的问题,linux重启后不能链接的问题 rabbitmq 服务启动问题 [bf@l ...
- ORA-01843: not a valid month
问题描述 ORA-01843: not a valid month oracle数据库插入出现无效的月份
- SpringBoot+springDataJpa实现单表字段动态部分更新
写在前面 所谓的动态部分更新是指:并非对数据记录的所有字段整体更新,而是知道运行时才确定哪个或者哪些字段需要被更新. 1)Spring Data Jpa对于Entity的更新,是对数据表中Entity ...
- android 获取颜色 getColor 方法 deprecated 过期
可以使用下面代码代替: ContextCompat.getColor(getContext(), R.color.post_list_content_color) 需要引入: compile 'com ...
- C#源码转PlantUml
1.下载编译开源工程PlantUmlClassDiagramGenerator 2.使用PlantUmlClassDiagramGenerator生成PlantUml文件 3.配置Vscode的Pla ...
- 关于Javaweb的比较好用的jar包概述
(连接数据库之前首先要导入这个数据库的驱动jar包 例如mysql 为mysql-connector-java-5.1.46.jar) 关于连接数据库的数据库连接池c3p0 jar包: c3p0-0 ...
- Jupyter Notebook 更改本地目录
首先如果使用anaconda直接安装jupyter notebook的话,直接在windows的cmd中输入jupyter notebook是没有用的,参见下图: 原因可能是anaconda代理了所有 ...
- 解决nginx报错:nginx: [emerg] bind() to 0.0.0.0:8088 failed (13: Permission denied)
报错描述: nginx: [emerg] bind() to 0.0.0.0:8088 failed (13: Permission denied) 通过ansible远程给主机更换端口并重新启动ng ...