英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论