Tensorflow 建模过程遇到的问题

Tensorflow 建模过程遇到的问题
1. 问题:运行出现Corrupt JPEG data: premature end of data segment Unsupported marker type 0xa6

 解决方案:
1.实际上是:我的图片是100*100 ,解码图片后超过了QImage的最大横竖像素大小65535,可以修改源码,添加代码如下:
 

import os
from os import listdir, path
import cv2

# 设置要调整的图像大小和目标分辨率
IMAGE_SIZE = (64, 64)
TARGET_MEAN = 0.5
TARGET_STD = 0.5

def check_and_adjust_images(folder_path):
    for file_name in listdir(folder_path):
        file_path = path.join(folder_path, file_name)
        # 如果是文件夹则继续遍历下属文件夹
        if path.isdir(file_path):
            check_and_adjust_images(file_path)
            continue
        if file_name.endswith(".jpg"):
            # 读取图像并调整大小
            image_path = os.path.join(folder_path, file_name)
            img = cv2.imread(image_path)
            img = cv2.resize(img, IMAGE_SIZE)

            # 归一化或标准化处理
            img = img.astype('float32') / 255.0  # 归一化处理
            img = (img - TARGET_MEAN) / TARGET_STD  # 标准化处理

            # 保存处理后的图像到目标路径
            target_path = os.path.join(folder_path, file_name)
            cv2.imwrite(target_path, img * 255.0)
            print(f"Processed image: {target_path}")

folder_path = "./dates/apple"#在此处更改你的路径
print("开始运行")
check_and_adjust_images(folder_path)

  • 6
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值