尝试调整文件中的图像大小时出现权限错误?

问题描述 投票:0回答:0

我正在 Tensorflow 中编写一个程序来猜测它是哪种花。有人告诉我,为了使程序更准确,我应该将所有图像的大小调整为相同的大小。我遇到了权限错误,但即使更改了所有权限以授予管理员权限,甚至在管理员命令提示符下运行,它仍然无法正常工作。在我使用“icacls”命令更改权限后,它也给了我一条成功消息。

import os
from PIL import Image

target_size = (224, 224)

for class_name in os.listdir('C:/Users/myname/OneDrive/Desktop/pyimportant/Automation/Flower Classification V2/V2/ Training Data'):
    class_dir = os.path.join('C:/Users/myname/OneDrive/Desktop/pyimportant/Automation/Flower Classification V2/V2/Training Data', class_name)
    for filename in os.listdir(class_dir):
        image_path = os.path.join(class_dir, filename)
        with Image.open(image_path) as img:
            img = img.resize(target_size)
            img.save(image_path)

如果您对规格等有任何疑问,我很乐意回答!

此外,如果您需要,这里是数据集:
https://www.kaggle.com/datasets/utkarshsaxenadn/flower-classification-5-classes-roselilyetc

python tensorflow permissions python-os
© www.soinside.com 2019 - 2024. All rights reserved.