第三章 3.1 表示图像 理解灰度图、RGB图和数组的关系
1.第一章: PyTorch计算机视觉实战:目标检测、图像处理与深度学习2.《Pytorch 最全入门介绍,Pytorch入门看这一篇就够了》学习3.第二章 2.3 使用Pytorch构建神经网络4.第二章 2.3.1 定义数据集训练神经网络5.第二章 2.4使用序贯方法构建神经网络nn.Sequential() 及打印神经网络模型摘要6.第二章 2.5 保存和加载文件中Pytorch模型
7.第三章 3.1 表示图像 理解灰度图、RGB图和数组的关系
8.第三章 3.3 使用pytorch的数据集9.第三章 3.4 训练神经网络10.第三章 3.6 批大小的影响11.第三章:3.8.1 绘制各层参数分布图 hist12.第三章 3.9 在训练过程中修改学习率13.第三章 3.10 构建更深的神经网络 比较有0、1、2隐含层的神经网络14.第三章 3.12 dropout 和 正则化 克服过拟合图片与脚本文件放在一个文件夹内,同级。
图片网上找一个就可以了。
# https://github.com/PacktPublishing/Modern-Computer-Vision-with-PyTorch # https://github.com/PacktPublishing/Modern-Computer-Vision-with-PyTorch ################### Chapter Three ####################################### # 第三章 灰度图和数组 import cv2, matplotlib.pyplot as plt import os ######################################################################## # 文件路径 file_path = 'meleon.jpg' #'C:/path/to/your/image/meleon.jpeg' # 替换为你的图像文件路径 # 检查文件是否存在 if not os.path.exists(file_path): print(f"Error: The file {file_path} does not exist.") else: img = cv2.imread('meleon.jpg') ######################################################################## # 检查图像是否成功读取 if img is None: print("Error: The image could not be read.") else: # 切片操作 #img = img[50:250, 40:240] # 转换为灰度图像 img_gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) # 显示图像 plt.imshow(img_gray, cmap='gray') #plt.show() img_gray_small = cv2.resize(img_gray, (16, 24)) plt.imshow(img_gray_small, cmap='gray') print(img_gray_small) plt.show() ######################################################################## #彩图与数组 # 文件路径 file_path = 'meleon.jpg' #'C:/path/to/your/image/meleon.jpeg' # 替换为你的图像文件路径 # 检查文件是否存在 if not os.path.exists(file_path): print(f"Error: The file {file_path} does not exist.") else: img = cv2.imread('meleon.jpg') # 检查图像是否成功读取 if img is None: print("Error: The image could not be read.") else: print(img.shape) crop = img[-3:,-3:] print(crop) plt.imshow(crop) plt.show() ########################################################################
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· .NET10 - 预览版1新功能体验(一)