吴裕雄 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 ...
随机推荐
- Linux system 初步
快捷键: open a new terminal: ctrl+alt+T; close current terminal: ctrl+shift+W; switch windows: alt+tab ...
- SSM开发基于Java EE在线图书销售系统
SSM(Spring+Spring MVC+MyBatis)开发基于Java EE在线图书销售系统 网站成功建立和运行很大部分取决于网站开发前的规划,因此为了在网站建立过程中避免一些不 ...
- 小tips:使用vue-cli脚手架搭建项目,关于eslint语法检测配置
配置文件在项目根目录里,文件名以 .eslintrc.* 为名. 为了兼容以前写的代码,避免修改太多代码,把不符合自己习惯的规则去掉,简单配置代码: module.exports = { root: ...
- jquery+layer实现无刷新、删除功能(laravel框架)
先来看一下效果 路由代码 Route::get('car/{id}/delete', 'CarController@delete'); 控制器层代码 //删除汽车信息 public function ...
- vue插槽(slot)的模板与JSX写法
vue官网API: 插槽:https://cn.vuejs.org/v2/guide/components-slots.html JSX:https://cn.vuejs.org/v2/guide/r ...
- OpenCV之Core组件进阶
颜色空间缩减 利用C++类型转换时向下取整操作,实现定义域内颜色缩减.表达式如下 Inew = (Iold/10)*10 简单的颜色空间缩减算法可由以下两步组成: (1)遍历图像矩阵的每个元素 (2) ...
- NOIP做题练习(day3)
A - 军队 问题描述 给定一个有 \(n\) 个队伍的人组成的序列,第 \(i\) 个队伍 \(i\) 有 \(s[i]\)个人组成,一个 \(l\) 到 \(r\)的子序列是合法的,当且仅当\(( ...
- Java 字符串、数值与16进制相互转化
字符串.数值与16进制相互转化 首先创建一个工具类: package c; public class DataUtils { /* * 字节数组转16进制字符串 */ public static St ...
- selenium的鼠标事件操作
自动化测试过程中,经常会用到鼠标事件,在selenium的action_chains模块的ActionChains定义了鼠标操作的一些事件,要使用ActionChains类中的方法,首先需要对Acti ...
- Promise简单实现(正常思路版)
转自: http://www.jianshu.com/p/473cd754311f Promise 看了些promise的介绍,还是感觉不够深入,这个在解决异步问题上是一个很好的解决方案,所以详细看一 ...