训练图片通道数的问题

训练图片集中混入4通道图片导致问题,移除这些图片后问题解决。使用cv2检查非3通道图片,cv2是OpenCV-Python的实现,主要讨论了图片的通道概念,RGB图像由红绿蓝三个通道组成,每个像素由三个数值控制对应显示器的亮度,影响最终颜色。了解并处理不同通道数的图片对于计算机视觉和神经网络训练至关重要。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Problem location: 在训练的图片集中,混入了几张4通道的图片,将这几张图片删除后问题解除。

使用cv2中img.shape列出非3通道图片的文件名:

import os
import numpy as np
import cv2

if __name__ == '__main__':

    root_dir = r'D:\WData\Workspace\springdemo\images\table_images\1.0\all_table'

    name = root_dir.split('\\')[-1]

    file_names = sorted(os.listdir(root_dir))
    for file in file_names:
        if file.endswith('.png'):
            img = cv2.imdecode(np.fromfile(os.path.join(root_dir, file), dtype=np.uint8), -1)
            size = img.shape

            if size[2] != 3:
                print("通道"+ str(size[2]) + file)
                    # os.remove(file)

supplementary knowledge

CV2

cv2 is OpenCV-python implements.

OpenCV-Python Tutorials

Win10 + anaconda安装cv2

pip install opencv-python

Images and Channels

Images are often referred to as RGB images that use channels. Channels are a very simple idea that is easy to use.

RGB Explained

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值