读取图像数据:通过append方法
原来通过np.concatenate方法拼接加载的数据,发现比较耗内存,现在改成通过append方法加载图像数据。
需要注意:通过append方法加载后的数据类型是list,要想喂给卷积神经网络训练,需要转换为np.ndarray类型。
import cv2
import numpy as np
'''ROI数据集'''
open_path = 'C:/Users/panansi/Desktop/easyAI'
read_path = 'C:/Users/panansi/Desktop/easyAI'x_test = []
y_test = []for line in open('{}/{}'.format(open_path,'/test/sick/sick.txt'), 'r'):file_name = line[:-3].replace('img','bmp')img = cv2.imread('{}/test/sick/{}'.format(read_path, file_name))#, flags=-1)img = img / 255.0img = img.astype(np.float32)x_test.append(img)y_test.append(1)#cv2.imwrite('{}/train/sick/{}'.format(write_path, file_name), img)
#############################################################################
i=0
for line in open('{}/{}'.format(open_path,'/test/unsick/unsick.txt'), 'r'):file_name = line[:-3].replace('img','bmp')img = cv2.imread('{}/test/unsick/{}'.format(read_path, file_name))#, flags=-1)img = img / 255.0img = img.astype(np.float32)x_test.append(img)y_test.append(0)for line in open('{}/{}'.format(open_path,'/train/sick/sick.txt'), 'r'):file_name = line[:-3].replace('img','bmp')img = cv2.imread('{}/train/sick/{}'.format(read_path, file_name))#, flags=-1)img = img / 255.0img = img.astype(np.float32)x_test.append(img)y_test.append(1)#cv2.imwrite('{}/train/sick/{}'.format(write_path, file_name), img)
#############################################################################
i=0
for line in open('{}/{}'.format(open_path,'/train/unsick/unsick.txt'), 'r'):file_name = line[:-3].replace('img','bmp')img = cv2.imread('{}/train/unsick/{}'.format(read_path, file_name))#, flags=-1)img = img / 255.0img = img.astype(np.float32)x_test.append(img)y_test.append(0)x_test = np.reshape(x_test, (len(x_test), x_test[1].shape[0], x_test[1].shape[1], x_test[1].shape[2]))
y_test = np.reshape(y_test, (len(y_test), 1))
读取图像数据:通过append方法相关推荐
- python读取图像数据的一些方法
工作和学习中设计一个神经网络中经常需要设计一个数据载入器.首先第一件事我们要根据我们的任务要求确定一个数据提供的方法.如我们是一个分类任务,我们就需要读取数据和数据本身对应的标签. 1 ...
- python读取图像数据流_浅谈TensorFlow中读取图像数据的三种方式
本文面对三种常常遇到的情况,总结三种读取数据的方式,分别用于处理单张图片.大量图片,和TFRecorder读取方式.并且还补充了功能相近的tf函数. 1.处理单张图片 我们训练完模型之后,常常要用图片 ...
- Kinect V1读取图像数据(For Windows)
Kinect V1读取图像数据(For Windows) 这篇博客 Kinect V1介绍 数据读取的基本流程 运行代码和注释 结尾 这篇博客 刚好有一台现成的Kinect V1相机,所以就拿过来学 ...
- TensorFlow中读取图像数据的三种方式(转)
附加一个链接关于DatasetAPI:https://zhuanlan.zhihu.com/p/30751039 本文面对三种常常遇到的情况,总结三种读取数据的方式,分别用于处理单张图片.大量图片,和 ...
- 目标检测:python实现多种图像数据增强的方法(光照,对比度,遮挡,模糊)
图像数据增强的内容(可根据需要自定义选择): 1.直方图均衡化 2.clahe自适应对比度直方图均衡化 3.白平衡 4.亮度增强 5.亮度,饱和度,对比度增强 6.去除图像上的高光部分 7.自适应亮度 ...
- pillow支持python 2和python 3_python3读取图像并可视化的方法(PIL/Pillow、opencv/cv2)...
原图: 使用TensorFlow做图像处理的时候,会对图像进行一些可视化的操作.下面,就来列举一些我知道的图像读取并可视化的方法. 1. Pillow模块 1.1 Pillow模块的前生 Pillow ...
- MATLAB调用工业相机读取图像数据
前言 项目中需要读出网口通信的工业相机的图像数据,此文主要是记个笔记. 参考链接 1.在Windows上使用MATLAB Image Acquisition Toolbox 2.调用相机程序 3.ma ...
- 深度学习图像数据增广方法总结
参考:Data Augmentation | How to use Deep Learning when you have Limited Data-Part 2 文章目录 1. 数据增广(Data ...
- opencv从内存缓冲区中读取图像数据
1.从内存中加载图像数据 s_Image_Info stDispImgInfo = spImgInfo->m_stDispInfo; //cv::_InputArray pic_arr(stDi ...
- Python 分通道读取图像数据,取经之路第 4 天
今天是持续写作的第 36 / 100 天. 如果你有想要交流的想法.技术,欢迎在评论区留言. 今天这 1 个小时,继续给大家打来 Python 读取图片这一简单的操作. 读取单通道 使用 OpenCV ...
最新文章
- Map再整理,从底层源码探究HashMap
- 确认AD DS域是否正常
- list中存储map的情况下,遍历list
- SpringBoot 整合 Thymeleaf 如何使用后台模板快速搭建项目
- windows拾取像素坐标_窗口坐标获取 windows
- Eclipse导入GitHub项目两处报错处理
- Spring系列(十三):AOP相关知识笔记
- imessage_重新设计iMessage以获得更好的用户体验— UX案例研究
- php 时间选择,PHP-在学说2中的日期之间选择条目
- 23_python基础—模块和包
- hbase 中文乱码 查询_如何在 HBase Shell 命令行正常查看十六进制编码的中文?哈哈~...
- 拓端tecdat|在Amazon Web Services中使用R语言运行模拟
- zabbix3.0.4安装部署文档(二)
- 转置卷积 反卷积 PyTorch torch.nn.ConvTranspose2d() output_padding
- Java中集合retainall_Collection中的之retainAll()方法的理解
- java 添加jbutton_在java中怎样在JLabel上添加JButton呢
- 如何衡量一篇英语作文词汇丰富度?
- 一个英语学渣是如何通过英语六级的
- 形容长得丑的30句经典句子
- ANSYS接触面与目标面的定义规则