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'>
相关推荐
JaydenAI13 小时前
[拆解LangChain执行引擎]三种持久化模式的差异
python·langchain
LaughingZhu13 小时前
Product Hunt 每日热榜 | 2026-02-17
大数据·数据库·人工智能·经验分享·搜索引擎
数据智能老司机13 小时前
Agentic Mesh——Agent 架构
人工智能·llm·agent
老赵全栈实战13 小时前
《从零搭建RAG系统第4天:问题向量化+Milvus检索匹配+结果优化》
python·ai编程
lynnss_ai13 小时前
针对 Vibe Coding 的提示工程技巧详细指南
人工智能·vibecoding
Katecat9966313 小时前
【葡萄病害检测】基于SABL-RetinaNet的葡萄叶片黑腐病、霜霉病、白粉病和锈病自动识别系统
python
华农DrLai13 小时前
向量嵌入入门:给每个词分配一个“数字指纹“
大数据·人工智能·ai·llm·rag
天辛大师13 小时前
天辛大师也谈神之视角,未来学AI全息大模型与预测原理
大数据·人工智能·决策树·随机森林·启发式算法
golang学习记13 小时前
Claude Opus 4.6 正式发布:Agent 时代的编程王者与长上下文革命
前端·人工智能·后端
数据智能老司机13 小时前
Agentic Mesh——智能体的前世今生与未来
人工智能·llm·agent