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

huangapple go评论72阅读模式
英文:

Getting a permission error while trying to resize images in a file?

问题

我正在使用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

英文:

I am making a program in Tensorflow to guess the type of flower it is. I was told that to make the program more accurate, I should resize all the images to the same size. I was getting a permission error, but even after changing all the permissions to give admin, and even running in admin Command Prompt, it still didn't work. It also gave me a success message after I used the "icacls" command to alter the permissions.

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)

If you have any questions about specs or such, I'd be happy to answer!

Also, in case you want, here's the dataset:
https://www.kaggle.com/datasets/utkarshsaxenadn/flower-classification-5-classes-roselilyetc

答案1

得分: 0

Turns out I had to restart my computer, and then it was working fine. Sorry for the inconvenience! I don't know why this would happen, but sometimes restarting just helps.

英文:

Turns out I had to restart my computer, and then it was working fine. Sorry for the inconvinience! I don't know why this would happen, but sometimes restarting just helps.

huangapple
  • 本文由 发表于 2023年2月19日 11:14:58
  • 转载请务必保留本文链接:https://go.coder-hub.com/75497774.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定