当前位置:网站首页>Convert multiple pictures into one NPY file storage
Convert multiple pictures into one NPY file storage
2022-06-11 06:12:00 【Glutinous rice balls】
In my recent experiment, I need to convert a data set that is all pictures into numpy stored , Then put in the model training .
First of all, there must be a .csv file , This file stores the names and categories of all pictures in the training set , There are two columns , When downloading some data sets, this file will be brought or handled for you to download , But it can also be generated by itself , You can see here ( Main points three )
import pandas as pd
import cv2
import numpy as np
# Read the file containing the picture name and the corresponding class alias .csv file
train = pd.read_csv('train_new.csv')
#print(train)
# Create an empty list , The back is used to store every picture in the training set
train_image = []
'''
csv There are two columns in the document , A list of picture names , A list of corresponding class aliases , Here is the name of the traversal image , in total 2408 Zhang
'''
for i in range(train.shape[0]):#2408
# Load image , Here go to the folder , Traverse csv The column name in the file is 'image' The column of , Picture name , Then read the picture
img_cv2 = cv2.imread('train_1_50/'+train['image'][i])
# Set the target size to (224,224,3)
image = cv2.resize(img_cv2,(224,224),interpolation=cv2.INTER_AREA)
# Pixel value normalization
img = image / 255
# Add the image to train_image list
train_image.append(img)
# Turn the list to numpy Array
X = np.array(train_image)#train_image There is 2408 A picture , All are numpy Format
# Check the size of the array
print(X.shape)
# View array
print(X)Refer to the blog post where the boss loads the image and sets the image size in one line of code , But with image.load_img Only pictures are read , And then turn it into numpy form , and cv2.imread It can be done in one step .( Why should I change it , Because I have been reporting mistakes in the way of big men , I can't solve , The private letter boss ignored me ,555...)
# Load image , And set the target size to (224,224,3)
img = image.load_img('train_1/'+train['image'][i], target_size=(224,224,3))
# Convert it to an array
img = image.img_to_array(img)Look at the effect :

There are so many here 0 Because my pictures are extracted from the video , Some of the extracted pictures are just the switching between the previous frame and the next frame , So it's black , No value , In addition, the array display is incomplete .

view list , It all shows up ...
边栏推荐
- Install Oracle Database
- FIFO最小深度计算的题目合集
- Cenos7 builds redis-3.2.9 and integrates jedis
- Goodbye 2021 Hello 2022
- Chapter 4 of machine learning [series] naive Bayesian model
- Yoyov5's tricks | [trick8] image sampling strategy -- Sampling by the weight of each category of the dataset
- Sqli-labs less-01
- Global case | how an airline with a history of 100 years can expand and transform to promote innovation in the aviation industry
- Build the first power cloud platform
- FPGA设计——乒乓操作实现与modelsim仿真
猜你喜欢

ERROR 1215 (HY000): Cannot add foreign key constraint

Login and registration based on servlet, JSP and MySQL

Super details to teach you how to use Jenkins to realize automatic jar package deployment
![Chapter 1 of machine learning [series] linear regression model](/img/e2/1f092d409cb57130125b0d59c8fd27.jpg)
Chapter 1 of machine learning [series] linear regression model

FIFO最小深度计算的题目合集

autojs,读取一行删除一行,停止自己外的脚本

Sqli-libs post injection question 11-17 actual combat

Which company is better in JIRA organizational structure management?

Graphsage paper reading
![[IOS development interview] operating system learning notes](/img/1d/2ec6857c833de00923d791f3a34f53.jpg)
[IOS development interview] operating system learning notes
随机推荐
What is a thread pool?
Graphsage paper reading
Functional interface lambda, elegant code development
FIFO最小深度计算的题目合集
The meaning in the status column displayed by PS aux command
Simple understanding of XML and JSON
Cenos7 builds redis-3.2.9 and integrates jedis
Twitter data collection (content, fans, keywords, etc.)
Record the first data preprocessing process
[must see for game development] 3-step configuration p4ignore + wonderful Q & A analysis (reprinted from user articles)
Servlet
ThymeleafEngine模板引擎
[daily exercise] 217 Duplicate element exists
Super explanation
SQLI_ LIBS range construction and 1-10get injection practice
Box model
The artistic director and production designer of Disney's Mandalorian revealed the virtual scene production behind it
qmake 实现QT工程pro脚本转vs解决方案
Shandong University machine learning experiment 7 pca+ SVM face recognition
FPGA面试题目笔记(一)——FPGA开发流程、亚稳态和竞争冒险、建立保持时间、异步FIFO深度等