Output Result Files to only 1 folder #272

Open
opened 2026-01-29 21:46:23 +00:00 by claunia · 1 comment
Owner

Originally created by @multifirez on GitHub (Oct 13, 2022).

Is there a way to only output files from (whole_imgs) to the (restored_imgs) folder, and not (cmp, cropped_faces, restored_faces) I don't need these other image sizes and it just makes the process take longer

Originally created by @multifirez on GitHub (Oct 13, 2022). Is there a way to only output files from (whole_imgs) to the (restored_imgs) folder, and not (cmp, cropped_faces, restored_faces) I don't need these other image sizes and it just makes the process take longer
Author
Owner

@qiufengchuiwoyisan commented on GitHub (Oct 19, 2022):

you can try replace the code like this

------------------------ restore ------------------------

restorer = GFPGANer(
model_path=model_path,
upscale=args.upscale,
arch=arch,
channel_multiplier=channel_multiplier,
bg_upsampler=bg_upsampler)

# ------------------------ restore ------------------------
if os.path.isdir(args.input):
    print("Read imagelist")
else:
    print("Error, input is not a dir!")
    return

dir_path = args.input
count = 0
deal = 0
dnum = 0
for root, dirs, files in os.walk(dir_path):
    for subdirname in dirs:
        dnum = dnum + 1
        new_path = os.path.join(args.output, subdirname)
        os.makedirs(new_path, exist_ok=True)
        dir = os.path.join(args.input, subdirname)
        for img in os.listdir(dir):
            img_name = os.path.join(dir, img)
            # 是否剔除原目标
            # if subdirname + '_0.jpg' == img:
            #     input_img = cv2.imread(img_name, cv2.IMREAD_COLOR)
            #     save_path = os.path.join(new_path, img)
            #     imwrite(input_img, save_path)
            #     continue
            count = count + 1
            input_img = cv2.imread(img_name, cv2.IMREAD_COLOR)
            cropped_faces, restored_faces, restored_img = restorer.enhance(
                     input_img, has_aligned=args.aligned, only_center_face=args.only_center_face, paste_back=True)

            # save restored img
            if restored_img is not None:
                save_restore_path = os.path.join(new_path, img)
                imwrite(restored_img, save_restore_path)
                deal = deal + 1
            else:
                print("Jump ", img_name)
                save_restore_path = os.path.join(new_path, img)
                imwrite(input_img, save_restore_path)
        print(dnum, '/', len(dirs), "is completed!")
print("Pic num:", count, "Deal num", deal)
@qiufengchuiwoyisan commented on GitHub (Oct 19, 2022): you can try replace the code like this # ------------------------ restore ------------------------ restorer = GFPGANer( model_path=model_path, upscale=args.upscale, arch=arch, channel_multiplier=channel_multiplier, bg_upsampler=bg_upsampler) # ------------------------ restore ------------------------ if os.path.isdir(args.input): print("Read imagelist") else: print("Error, input is not a dir!") return dir_path = args.input count = 0 deal = 0 dnum = 0 for root, dirs, files in os.walk(dir_path): for subdirname in dirs: dnum = dnum + 1 new_path = os.path.join(args.output, subdirname) os.makedirs(new_path, exist_ok=True) dir = os.path.join(args.input, subdirname) for img in os.listdir(dir): img_name = os.path.join(dir, img) # 是否剔除原目标 # if subdirname + '_0.jpg' == img: # input_img = cv2.imread(img_name, cv2.IMREAD_COLOR) # save_path = os.path.join(new_path, img) # imwrite(input_img, save_path) # continue count = count + 1 input_img = cv2.imread(img_name, cv2.IMREAD_COLOR) cropped_faces, restored_faces, restored_img = restorer.enhance( input_img, has_aligned=args.aligned, only_center_face=args.only_center_face, paste_back=True) # save restored img if restored_img is not None: save_restore_path = os.path.join(new_path, img) imwrite(restored_img, save_restore_path) deal = deal + 1 else: print("Jump ", img_name) save_restore_path = os.path.join(new_path, img) imwrite(input_img, save_restore_path) print(dnum, '/', len(dirs), "is completed!") print("Pic num:", count, "Deal num", deal)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: TencentARC/GFPGAN#272