-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpng_to_jpg.py
32 lines (28 loc) · 1.03 KB
/
png_to_jpg.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
from PIL import Image
import tensorflow as tf
AUTOTUNE = tf.data.experimental.AUTOTUNE
import pathlib
import random
import os
#
folder_name = "MoeLoader +1s"
# 导入数据
data_root_orig = tf.keras.utils.get_file(origin='C:/Users/76067/.keras/datasets/'+folder_name+'.zip', fname=folder_name)
data_root = pathlib.Path(data_root_orig)
# 解析
all_image_paths = list(data_root.glob('*/*'))
all_image_paths = [str(path) for path in all_image_paths]
random.shuffle(all_image_paths)
# 图片总数
image_count = len(all_image_paths)
for img_index in range(len(all_image_paths)):
img_is_png = all_image_paths[img_index].endswith(".png")
if img_is_png:
print(all_image_paths[img_index].replace(".png", ".jpg"))
image = Image.open(all_image_paths[img_index])
image_rgb = image.convert('RGB')
image_rgb.save(all_image_paths[img_index].replace(".png", ".jpg"))
# 移除
os.remove(all_image_paths[img_index])
# print(all_image_paths[img_index])
print("Done")