python处理mat数据和处理png的区别_Python---利用scipy.misc等库对jpg以及png等图像数据预处理(用于深度学习喂数据)...
转载自:http://blog.csdn.net/qq_16949707/article/details/56306720import os
import glob
image_dir = "D:\\data\\ADEChallengeData2016"
file_glob = os.path.join(image_dir, "images", "training", '*.' + 'jpg')
file_list = []
file_list.extend(glob.glob(file_glob))
1
2
3
4
5
6
file_list_test = file_list[0:10]
1
import random
random.shuffle(file_list_test)
1
2
import numpy as np
import scipy.misc as misc
1
2
def read_and_transform(filename):
image = misc.imread(filename)
resize_image = misc.imresize(image,[224, 224], interp='nearest')
return np.array(resize_image)
1
2
3
4
images = np.array([read_and_transform(filename) for filename in file_list_test])
1
def find_annotations_image_path(image_path):
return image_path.replace("images","annotations").replace("jpg","png")
1
2
annotations_file_list_test = [find_annotations_image_path(image_path) for image_path in file_list_test]
1
annotations = np.array([np.expand_dims(read_and_transform(filename), axis=3) for filename in annotations_file_list_test])
1
batch_offset = 0
1
def next_batch(batch_size,batch_offset,images,annotations,epochs_completed):
start = batch_offset
batch_offset += batch_size
if batch_offset > images.shape[0]:
# Finished epoch
epochs_completed += 1
print("****************** Epochs completed: " + str(epochs_completed) + "******************")
# Shuffle the data
perm = np.arange(images.shape[0])
np.random.shuffle(perm)
images = images[perm]
annotations = annotations[perm]
# Start next epoch
start = 0
batch_offset = batch_size
end = batch_offset
print start,end
# return images[start:end], self.annotations[start:end]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
2 测试
2.1 测试next_batch送数据
next_batch(2,0,images,annotations,0)
1
0 2
1
2
next_batch(2,2,images,annotations,0)
1
2 4
1
2
next_batch(2,10,images,annotations,0)
1
****************** Epochs completed: 1******************
0 2
1
2
3
2.2 测试shuffle打乱数据
perm = np.arange(images.shape[0])
1
print perm
1
[0 1 2 3 4 5 6 7 8 9]
1
2
np.random.shuffle(perm)
1
print perm
1
[5 3 9 4 8 6 2 1 7 0]
1
2
images[0]
1
array([[[ 92, 57, 27],
[181, 145, 113],
[227, 189, 153],
...,
[100, 77, 71],
[200, 177, 171],
[194, 174, 167]],
[[ 82, 45, 18],
[ 85, 46, 17],
[176, 136, 101],
...,
[200, 177, 171],
[192, 172, 165],
[180, 160, 153]],
[[ 88, 47, 25],
[ 93, 53, 28],
[131, 90, 60],
...,
[202, 182, 175],
[201, 181, 174],
[163, 144, 137]],
...,
[[ 99, 48, 31],
[ 84, 33, 16],
[ 81, 30, 13],
...,
[170, 134, 108],
[166, 130, 104],
[163, 127, 101]],
[[ 67, 16, 0],
[ 98, 47, 30],
[ 97, 46, 29],
...,
[168, 132, 106],
[173, 137, 111],
[168, 132, 106]],
[[ 62, 11, 0],
[ 83, 32, 15],
[ 65, 14, 0],
...,
[169, 133, 107],
[164, 128, 102],
[165, 129, 103]]], dtype=uint8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
images = images[perm]
annotations = annotations[perm]
1
2
images[0]
1
array([[[ 50, 75, 80],
[ 50, 75, 80],
[ 51, 76, 81],
...,
[135, 165, 176],
[133, 163, 174],
[133, 163, 174]],
[[ 50, 75, 80],
[ 50, 75, 80],
[ 51, 76, 81],
...,
[135, 165, 176],
[133, 163, 174],
[133, 163, 174]],
[[ 49, 74, 79],
[ 49, 74, 79],
[ 50, 75, 80],
...,
[135, 165, 176],
[133, 163, 174],
[133, 163, 174]],
...,
[[ 4, 16, 12],
[ 4, 16, 12],
[ 4, 16, 12],
...,
[176, 196, 205],
[177, 197, 206],
[178, 198, 207]],
[[ 4, 16, 12],
[ 4, 16, 12],
[ 4, 16, 12],
...,
[175, 195, 204],
[176, 196, 205],
[176, 196, 205]],
[[ 4, 16, 12],
[ 4, 16, 12],
[ 4, 16, 12],
...,
[177, 197, 206],
[176, 196, 205],
[176, 196, 205]]], dtype=uint8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
2.3 测试np.expand_dims
annotations1 = np.array([read_and_transform(filename) for filename in annotations_file_list_test])
1
annotations1.shape
1
(10L, 224L, 224L)
1
2
annotations.shape
1
(10L, 224L, 224L, 1L)
1
2
annotations_file_list_test[0]
1
'D:\\data\\ADEChallengeData2016\\annotations\\training\\ADE_train_00000007.png'
1
2
file_list_test[0]
1
'D:\\data\\ADEChallengeData2016\\images\\training\\ADE_train_00000007.jpg'
1
2
image_path = annotations_file_list_test[0]
1
annotations_image = read_and_transform(image_path)
1
annotations_image.shape
1
(224L, 224L)
1
2
annotations_image
1
array([[ 0, 1, 1, ..., 6, 6, 6],
[135, 135, 135, ..., 6, 6, 6],
[ 0, 135, 135, ..., 6, 6, 6],
...,
[ 0, 11, 11, ..., 4, 4, 4],
[ 0, 11, 11, ..., 4, 4, 4],
[ 0, 11, 11, ..., 4, 4, 4]], dtype=uint8)
1
2
3
4
5
6
7
8
np.expand_dims(annotations_image,axis=3)
1
array([[[ 0],
[ 1],
[ 1],
...,
[ 6],
[ 6],
[ 6]],
[[135],
[135],
[135],
...,
[ 6],
[ 6],
[ 6]],
[[ 0],
[135],
[135],
...,
[ 6],
[ 6],
[ 6]],
...,
[[ 0],
[ 11],
[ 11],
...,
[ 4],
[ 4],
[ 4]],
[[ 0],
[ 11],
[ 11],
...,
[ 4],
[ 4],
[ 4]],
[[ 0],
[ 11],
[ 11],
...,
[ 4],
[ 4],
[ 4]]], dtype=uint8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
image_path.replace("images","annotations").replace("jpg","png")
1
'D:\\data\\ADEChallengeData2016\\annotations\\training\\ADE_train_00000007.png'
1
2
annotations_image_path = image_path.replace("images","annotations").replace("jpg","png")
1
annotations_image_dir = "D:\\data\\ADEChallengeData2016"
annotations_file_glob = os.path.join(image_dir, "annotations", "training", '*.' + 'png')
annotations_file_list = []
annotations_file_list.extend(glob.glob(file_glob))
1
2
3
4
len(annotations_file_list)
1
20210
1
2
annotations = np.array([np.expand_dims(read_and_transform(filename), axis=3) for filename in file_list_test])
1
annotations.shape
1
(10L, 224L, 224L, 3L, 1L)
1
2
len(images)
1
10
1
2
image_array = read_and_transform(file_list_test[0])
1
len(image_array)
1
224
1
2
image_array[0][:][:].shape
1
(224L, 3L)
1
2
image_array.shape
1
(224L, 224L, 3L)
1
2
2.4 测试misc的imread以及imresize
image = misc.imread(file_list_test[0])
1
image.shape
1
(735L, 512L, 3L)
1
2
resize_image = misc.imresize(image,[224, 224], interp='nearest')
1
import matplotlib.pyplot as plt
plt.figure()
plt.imshow(image)
plt.show()
1
2
3
4
import matplotlib.pyplot as plt
plt.figure()
plt.imshow(resize_image)
plt.show()
1
2
3
4
misc.imshow(image)
1
---------------------------------------------------------------------------
RuntimeError Traceback (most recent call last)
in ()
----> 1 misc.imshow(image)
D:\software\Anaconda2\lib\site-packages\scipy\misc\pilutil.pyc in imshow(arr)
440 os.unlink(fname)
441 if status != 0:
--> 442 raise RuntimeError('Could not execute image viewer.')
443
444
RuntimeError: Could not execute image viewer.
本文同步分享在 博客“Trent1985”(CSDN)。
如有侵权,请联系 support@oschina.cn 删除。
本文参与“OSC源创计划”,欢迎正在阅读的你也加入,一起分享。
python处理mat数据和处理png的区别_Python---利用scipy.misc等库对jpg以及png等图像数据预处理(用于深度学习喂数据)...相关推荐
- 【转载】利用scipy.misc等库对jpg以及png等图像数据预处理(用于深度学习喂数据)...
http://blog.csdn.net/qq_16949707/article/details/56306720 转载于:https://www.cnblogs.com/tenderwx/p/805 ...
- 独家 | SVP:一种用于深度学习的高效数据选择方法
作者:Cody Coleman, Peter Bailis, and Matei Zaharia 翻译:杨毅远 校对:王琦 本文长度为1800字,建议阅读7分钟 本文为你介绍SVP方法如何在保证识别准 ...
- MATLAB中深度学习的数据集合
简 介: 本文总结了部分MATLAB中用于深度学习的数据集合. 关键词: MATLAB,DEEPLENARING #mermaid-svg-xPWl4yTsAw5Z4HFe {font-family: ...
- 回归素材(part9)--PYTHON机器学习手册-从数据预处理到深度学习
学习笔记,仅供参考,有错必纠 PYTHON机器学习手册-从数据预处理到深度学习 通过正则化减少方差 我们可以使用岭回归或者Lasso回归,介绍回归模型的方差.
- Python批量处理表格有用吗_python批量读入图片、处理并批量输出(可用于深度学习训练集的制作)...
最近工作实在是太忙了,白浪花的项目没有及时跟进,很多知识也没有自学.好了,趁着现在等领导回复微信的时间,我把上周趁着零散时间做的工作总结一下.内容依然小白,但是却很重要. 项目情况简单描述一下,最终要 ...
- 30个顶级Python库 | 用于深度学习、自然语言处理和计算机视觉
CDA数据分析师 出品 作者:Matthew Mayo 编译:Mika 今天我们来盘点一下有哪些用于深度学习.自然语言处理和计算机视觉的顶级Python库. 我们尽力将每个库按预期的使用情况进行归类, ...
- amd python mkl_AMD用于深度学习到底Yes吗? 基于mkl和openblas的numpy运算速度小测与安装教程...
AMD最近几年似乎是太Yes了,2016年到现在,股价从2块钱涨到40块钱,在很多地区的DIY市场份额超过英特尔,苏妈NB啊! 但在科学计算领域,CPU没有相关的配套软件支持是不行的.想自己组装个深度 ...
- 30个顶级Python库:用于深度学习、自然语言处理和计算机视觉
今天我们来盘点一下有哪些用于深度学习.自然语言处理和计算机视觉的顶级Python库. 我们尽力将每个库按预期的使用情况进行归类,希望这能对大家有所帮助. 显然,现在并不是所有的自然语言处理和计算机视觉 ...
- DL:关于深度学习常用数据集中训练好的权重文件(Deeplab v3、MobileNet、InceptionV3、VGG系列、ResNet、Mask R-CNN )下载地址集合(持续更新)
DL:关于深度学习常用数据集中训练好的权重文件(Deeplab v3.MobileNet.InceptionV3.VGG系列.ResNet.Mask R-CNN )下载地址集合(持续更新) 目录 基于 ...
最新文章
- python3 tkinter电子书_python3 tkinter实现添加图片和文本
- STM32 进阶教程 18 – ADC间断模式
- 电脑任务栏跑到右边去了_浙江电脑硬盘维修收费标准,请看
- 为什么Go没有三元运算符
- 7.组件连线(贝塞尔曲线)--从零起步实现基于Html5的WEB设计器Jquery插件(含源码)...
- 工作331:uni-修改未完成数据动态渲染
- eclipse弃坑记第一篇之在idea上配置Tomcat环境并创建Javaweb项目的详细步骤原创
- java并发编程——线程池的工作原理与源码解读
- [vc中文绿色版本]33.8 MB下载
- 华为公开折叠屏新专利:Mate X2有望首发搭载
- 【2018-2019-1】20165223-20165218 实验二 固件程序设计
- python心跳包原理_Python 用心跳(UDP包)探测不活动主机
- KD树(网易游戏笔试)
- Python爬取携程和同程的景点评论并实现词云
- 电脑蓝牙打电话-总结(篇外、虚拟声卡选型)
- 谷歌浏览器导致电脑右下角莫名弹出广告解决办法
- c语言天数倒计时软件,c语言 日期倒计时 日期计算器
- 存储emoji表情或特殊字符报错(Incorrect string value: ‘\xF0\x9F\x98\x82\xF0\x9F...‘)
- Linux命令之pwd
- python实现爬虫探探_全栈 - 9 实战 爬取豆瓣电影数据
热门文章
- 面试中精华,俺自己总结的
- Vue中数组变动监听
- 从资深遥控器在家工作的5个技巧
- DevOps vs Agile:有什么区别?
- oracle 编程必读_现在学习的编程语言,网络监视工具,备份解决方案以及更多必读内容
- 软件开发安全性_开发具有有效安全性的软件的最佳方法
- 前端:CSS/13/HTML引入CSS的方法,CSS表格属性,盒子模型,上下外边距合并
- Bootstrap 打印机类
- es6 Generator函数的应用
- C语言printf()、sprintf()、vsprintf() 的区别与联系