2
0
mirror of https://github.com/Shawn-Shan/fawkes.git synced 2024-12-22 07:09:33 +05:30

Added an option to directly replace the original file, preserving format.

This commit is contained in:
Daniel Smith 2020-09-26 16:11:21 -07:00
parent e3b2181949
commit 987e7e2ce6
2 changed files with 14 additions and 5 deletions

View File

@ -34,6 +34,7 @@ when --mode is `custom`:
* `--lr` : learning rate for the optimization * `--lr` : learning rate for the optimization
* `--feature-extractor` : name of the feature extractor to use * `--feature-extractor` : name of the feature extractor to use
* `--separate_target` : whether select separate targets for each faces in the diectory. * `--separate_target` : whether select separate targets for each faces in the diectory.
* `--no-rename-file` : option to directly replace the original file, keeping the same format. If used, format option is ignored.
### Example ### Example

View File

@ -84,7 +84,7 @@ class Fawkes(object):
return th, max_step, lr return th, max_step, lr
def run_protection(self, image_paths, mode='min', th=0.04, sd=1e9, lr=10, max_step=500, batch_size=1, format='png', def run_protection(self, image_paths, mode='min', th=0.04, sd=1e9, lr=10, max_step=500, batch_size=1, format='png',
separate_target=True, debug=False, no_align=False): separate_target=True, debug=False, no_align=False, no_rename=False):
if mode == 'custom': if mode == 'custom':
pass pass
else: else:
@ -147,6 +147,12 @@ class Fawkes(object):
reverse_process_cloaked(original_images)) reverse_process_cloaked(original_images))
for p_img, path in zip(final_images, image_paths): for p_img, path in zip(final_images, image_paths):
if no_rename:
format = path.split(".")[-1]
if format == 'jpg':
format = 'jpeg'
dump_image(p_img, path, format=format)
else:
file_name = "{}_{}_cloaked.{}".format(".".join(path.split(".")[:-1]), mode, format) file_name = "{}_{}_cloaked.{}".format(".".join(path.split(".")[:-1]), mode, format)
dump_image(p_img, file_name, format=format) dump_image(p_img, file_name, format=format)
@ -197,6 +203,8 @@ def main(*argv):
parser.add_argument('--format', type=str, parser.add_argument('--format', type=str,
help="format of the output image", help="format of the output image",
default="png") default="png")
parser.add_argument('--no-rename-file', help="option to directly replace the original file, keeping the same format. If used, format option is ignored",
action='store_true')
args = parser.parse_args(argv[1:]) args = parser.parse_args(argv[1:])
@ -213,12 +221,12 @@ def main(*argv):
protector.run_protection(image_paths, mode=mode, th=args.th, sd=args.sd, lr=args.lr, protector.run_protection(image_paths, mode=mode, th=args.th, sd=args.sd, lr=args.lr,
max_step=args.max_step, max_step=args.max_step,
batch_size=args.batch_size, format=args.format, batch_size=args.batch_size, format=args.format,
separate_target=args.separate_target, debug=args.debug, no_align=args.no_align) separate_target=args.separate_target, debug=args.debug, no_align=args.no_align, no_rename=args.no_rename_file)
else: else:
protector.run_protection(image_paths, mode=args.mode, th=args.th, sd=args.sd, lr=args.lr, protector.run_protection(image_paths, mode=args.mode, th=args.th, sd=args.sd, lr=args.lr,
max_step=args.max_step, max_step=args.max_step,
batch_size=args.batch_size, format=args.format, batch_size=args.batch_size, format=args.format,
separate_target=args.separate_target, debug=args.debug, no_align=args.no_align) separate_target=args.separate_target, debug=args.debug, no_align=args.no_align, no_rename=args.no_rename_file)
if __name__ == '__main__': if __name__ == '__main__':