From 79b20af3f23fc9ab685d645105de8728e8d2fbef Mon Sep 17 00:00:00 2001 From: Qing Date: Sun, 26 Feb 2023 16:36:19 +0800 Subject: [PATCH] auto delete wrong model --- lama_cleaner/helper.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/lama_cleaner/helper.py b/lama_cleaner/helper.py index 09ece1a..71ef72b 100644 --- a/lama_cleaner/helper.py +++ b/lama_cleaner/helper.py @@ -70,10 +70,16 @@ def ceil_modulo(x, mod): def handle_error(model_path, model_md5, e): _md5 = md5sum(model_path) if _md5 != model_md5: - logger.error( - f"Model md5: {_md5}, expected: {model_md5}, please delete {model_path} and restart lama-cleaner." - f"If you still have errors, please try download model manually first https://lama-cleaner-docs.vercel.app/install/download_model_manually.\n" - ) + try: + os.remove(model_path) + logger.error( + f"Model md5: {_md5}, expected md5: {model_md5}, wrong model deleted. Please restart lama-cleaner." + f"If you still have errors, please try download model manually first https://lama-cleaner-docs.vercel.app/install/download_model_manually.\n" + ) + except: + logger.error( + f"Model md5: {_md5}, expected md5: {model_md5}, please delete {model_path} and restart lama-cleaner." + ) else: logger.error( f"Failed to load model {model_path},"