pytorch读取图片的两种方式

一、利用PIL读取

python 复制代码
from PIL import Image
img_path="data/train/ants_image/0013035.jpg"
img_PIL=Image.open(img_path)
print(type(img_PIL))

输出:

python 复制代码
<class 'PIL.JpegImagePlugin.JpegImageFile'>

二、利用opencv读取

python 复制代码
import cv2
img_path="data/train/ants_image/0013035.jpg"
img_array = cv2.imread(img_path)
print(type(img_array))

输出:

python 复制代码
<class 'numpy.ndarray'>
相关推荐
2143965几秒前
怎么为MongoDB事务调优:将读操作尽量移到事务外面执行
jvm·数据库·python
计算机魔术师4 分钟前
【AI面试八股文 | 面试题库】AI工程师面试题库:100+来源的系统性解题思路
人工智能·面试·职场和发展·ai工程师面试·system design
飞哥数智坊5 分钟前
Harness Engineering 初接触的一些思考
人工智能·ai编程
天一生水water5 分钟前
RNN循环神经网络关键知识点
人工智能·rnn·深度学习
曲幽6 分钟前
FastAPI服务半夜又挂了?先别急着重启,查查你的数据库连接池“池子”是不是漏了
python·prometheus·fastapi·web·async·sqlalchemy·connection·pool
飞哥数智坊6 分钟前
都 2026 了,AI Agent 为什么偏偏选中了 CLI?
人工智能·ai编程
baidu_340998827 分钟前
JavaScript中函数式编程中不可变性与闭包的关联
jvm·数据库·python
石去皿8 分钟前
应届生如何从0到1进入AI岗位(LLM / RAG / Agent / 具身智能全路径)
人工智能
djjdjdjdjjdj8 分钟前
c++如何利用std--tie实现多个文件属性字段的快速比较排序【详解】
jvm·数据库·python
Y学院9 分钟前
当数字世界不再安全:2026,我们正站在网络安全的悬崖边
人工智能·安全·web安全