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)