增加了相似菜品预览功能,更完整了,交互更方便了。
This commit is contained in:
@@ -27,24 +27,24 @@ for class_name in os.listdir(input_root):
|
||||
input_dir = os.path.join(input_root, class_name)
|
||||
output_dir = os.path.join(output_root, class_name)
|
||||
os.makedirs(output_dir, exist_ok=True)
|
||||
if class_name == "麻婆豆腐":
|
||||
# 读取类别下所有图片路径
|
||||
img_files = [f for f in os.listdir(input_dir) if f.lower().endswith(('.jpg', '.png', '.jpeg'))]
|
||||
img_paths = [os.path.join(input_dir, f) for f in img_files]
|
||||
|
||||
# 读取类别下所有图片路径
|
||||
img_files = [f for f in os.listdir(input_dir) if f.lower().endswith(('.jpg', '.png', '.jpeg'))]
|
||||
img_paths = [os.path.join(input_dir, f) for f in img_files]
|
||||
print(f"类别 {class_name} 原始图片数: {len(img_paths)}")
|
||||
|
||||
print(f"类别 {class_name} 原始图片数: {len(img_paths)}")
|
||||
count = 0
|
||||
while count < target_num:
|
||||
img_path = random.choice(img_paths)
|
||||
img = Image.open(img_path).convert("RGB")
|
||||
# 生成增强图
|
||||
aug_img = transform(img)
|
||||
# 保存
|
||||
save_path = os.path.join(output_dir, f"aug_{count:03d}.jpg")
|
||||
aug_img.save(save_path)
|
||||
count += 1
|
||||
|
||||
count = 0
|
||||
while count < target_num:
|
||||
img_path = random.choice(img_paths)
|
||||
img = Image.open(img_path).convert("RGB")
|
||||
# 生成增强图
|
||||
aug_img = transform(img)
|
||||
# 保存
|
||||
save_path = os.path.join(output_dir, f"aug_{count:03d}.jpg")
|
||||
aug_img.save(save_path)
|
||||
count += 1
|
||||
|
||||
print(f"类别 {class_name} 已扩充到 {target_num} 张,保存于 {output_dir}")
|
||||
print(f"类别 {class_name} 已扩充到 {target_num} 张,保存于 {output_dir}")
|
||||
|
||||
print("✅ 数据增强完成!")
|
||||
|
||||
Reference in New Issue
Block a user