我是Python新手,需要在数据集上训练模型。我在同一位置找到了笔记本和数据集,并对笔记本进行了适当的更改以运行存储中的数据。代码在1后的训练阶段失败纪元以“图形执行错误”完成
这是我的 jupyter 笔记本:https://github.com/Megahedron69/wasteSegregationmodel
这是数据集:https://www.kaggle.com/datasets/aashidutt3/waste-segregation-image-dataset
这是原始笔记本:https://www.kaggle.com/code/gpiosenka/waste-f1-score-97
感谢@Dr.史努比答案。我的数据集中有损坏的图像,因此在我的根目录中使用了一个简单的 python 脚本来删除截断的图像
#pip install pillow
from PIL import Image
import os
def find_truncated_images(dataset_dir):
truncated_images = []
for root, _, files in os.walk(dataset_dir):
for filename in files:
file_path = os.path.join(root, filename)
try:
with Image.open(file_path) as img:
img.load()
except (IOError, OSError) as e:
# Log the file path if it's a truncated image
print(f"Truncated image: {file_path}")
truncated_images.append(file_path)
return truncated_images
def remove_truncated_images(truncated_images):
for file_path in truncated_images:
try:
os.remove(file_path)
print(f"Removed: {file_path}")
except OSError as e:
print(f"Error removing {file_path}: {e}")
if __name__ == "__main__":
dataset_dir = "." # Set the path to your dataset directory
truncated_images = find_truncated_images(dataset_dir)
remove_truncated_images(truncated_images)