Fix model paths

* move SAM2 models to models/sam2, to mirror the .../ComfyUI/models/sam2
  directory structure
* fix the command-line interface
* add masked output images to the test/ directory
This commit is contained in:
Jan Minar
2024-09-30 03:04:22 +00:00
parent 8ef5c9a74e
commit 8432c4a772
9 changed files with 7 additions and 5 deletions
+7 -5
View File
@@ -77,12 +77,14 @@ if __name__ == "__main__":
# import rdancer_debug # will listen for debugger to attach
def my_process_image(image_path, prompt):
from utils.sam import SAM_CHECKPOINT
image = Image.open(image_path).convert("RGB")
annotated_image, mask = process_image(image, prompt)
output_image_path, output_mask_path = f"output_image_{os.path.basename(image_path)}", f"output_mask_{os.path.basename(image_path)}"
annotated_image, mask, masked_image = process_image(SAM_CHECKPOINT, image, prompt)
output_image_path, output_mask_path, output_masked_image_path = f"output_image_{os.path.basename(image_path)}", f"output_mask_{os.path.basename(image_path)}", f"output_masked_image_{os.path.basename(image_path)}"
annotated_image.save(output_image_path)
mask.save(output_mask_path)
return output_image_path, output_mask_path
masked_image.save(output_masked_image_path)
return output_image_path, output_mask_path, output_masked_image_path
if len(sys.argv) < 2:
print(f"Usage: python {os.path.basename(sys.argv[0])} <image_path>[ ...] [<prompt>]")
@@ -110,6 +112,6 @@ if __name__ == "__main__":
from app import process_image
for image in images:
output_image_path, mask_path = my_process_image(image, prompt)
print(f"Saved output image to {output_image_path} and mask to {mask_path}")
output_image_path, output_mask_path, output_masked_image_path = my_process_image(image, prompt)
print(f"Saved output image to {output_image_path} and mask to {output_mask_path} and masked image to {output_masked_image_path}")

Before

Width:  |  Height:  |  Size: 590 KiB

After

Width:  |  Height:  |  Size: 590 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 98 KiB

Before

Width:  |  Height:  |  Size: 458 KiB

After

Width:  |  Height:  |  Size: 458 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 97 KiB