mirror of
https://github.com/Haoming02/sd-webui-old-photo-restoration.git
synced 2026-04-29 18:51:38 +00:00
commit cd7a9c103d1ea981ecd236d4e9111fd3c1cd6c2b Author: Haoming <hmstudy02@gmail.com> Date: Tue Dec 19 11:33:44 2023 +0800 add README commit 30127cbb2a8e5f461c540729dc7ad457f66eb94c Author: Haoming <hmstudy02@gmail.com> Date: Tue Dec 19 11:12:16 2023 +0800 fix Face Enhancement distortion commit 6d52de5368c6cfbd9342465b5238725c186e00b9 Author: Haoming <hmstudy02@gmail.com> Date: Mon Dec 18 18:27:25 2023 +0800 better? args handling commit 0d1938b59eb77a038ee0a91a66b07fb9d7b3d6d4 Author: Haoming <hmstudy02@gmail.com> Date: Mon Dec 18 17:40:19 2023 +0800 bug fix related to Scratch commit 8315cd05ffeb2d651b4c57d70bf04b413ca8901d Author: Haoming <hmstudy02@gmail.com> Date: Mon Dec 18 17:24:52 2023 +0800 implement step 2 ~ 4 commit a5feb04b3980bdd80c6b012a94c743ba48cdfe39 Author: Haoming <hmstudy02@gmail.com> Date: Mon Dec 18 11:55:20 2023 +0800 process scratch commit3b18f7b042Author: Haoming <hmstudy02@gmail.com> Date: Wed Dec 13 11:57:20 2023 +0800 "init" commitd0148e0e82Author: Haoming <hmstudy02@gmail.com> Date: Wed Dec 13 10:34:39 2023 +0800 clone repo
63 lines
1.9 KiB
Python
63 lines
1.9 KiB
Python
# Copyright (c) Microsoft Corporation.
|
|
# Licensed under the MIT License.
|
|
|
|
import os
|
|
import struct
|
|
from PIL import Image
|
|
|
|
IMG_EXTENSIONS = [
|
|
'.jpg', '.JPG', '.jpeg', '.JPEG',
|
|
'.png', '.PNG', '.ppm', '.PPM', '.bmp', '.BMP',
|
|
]
|
|
|
|
|
|
def is_image_file(filename):
|
|
return any(filename.endswith(extension) for extension in IMG_EXTENSIONS)
|
|
|
|
|
|
def make_dataset(dir):
|
|
images = []
|
|
assert os.path.isdir(dir), '%s is not a valid directory' % dir
|
|
|
|
for root, _, fnames in sorted(os.walk(dir)):
|
|
for fname in fnames:
|
|
if is_image_file(fname):
|
|
#print(fname)
|
|
path = os.path.join(root, fname)
|
|
images.append(path)
|
|
|
|
return images
|
|
|
|
### Modify these 3 lines in your own environment
|
|
indir="/home/ziyuwan/workspace/data/temp_old"
|
|
target_folders=['VOC','Real_L_old','Real_RGB_old']
|
|
out_dir ="/home/ziyuwan/workspace/data/temp_old"
|
|
###
|
|
|
|
if os.path.exists(out_dir) is False:
|
|
os.makedirs(out_dir)
|
|
|
|
#
|
|
for target_folder in target_folders:
|
|
curr_indir = os.path.join(indir, target_folder)
|
|
curr_out_file = os.path.join(os.path.join(out_dir, '%s.bigfile'%(target_folder)))
|
|
image_lists = make_dataset(curr_indir)
|
|
image_lists.sort()
|
|
with open(curr_out_file, 'wb') as wfid:
|
|
# write total image number
|
|
wfid.write(struct.pack('i', len(image_lists)))
|
|
for i, img_path in enumerate(image_lists):
|
|
# write file name first
|
|
img_name = os.path.basename(img_path)
|
|
img_name_bytes = img_name.encode('utf-8')
|
|
wfid.write(struct.pack('i', len(img_name_bytes)))
|
|
wfid.write(img_name_bytes)
|
|
#
|
|
# # write image data in
|
|
with open(img_path, 'rb') as img_fid:
|
|
img_bytes = img_fid.read()
|
|
wfid.write(struct.pack('i', len(img_bytes)))
|
|
wfid.write(img_bytes)
|
|
|
|
if i % 1000 == 0:
|
|
print('write %d images done' % i) |