Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Colab Demo] Inference for a set of images by CenterNet #394

Open
TakuyaYashima opened this issue Aug 29, 2023 · 2 comments
Open

[Colab Demo] Inference for a set of images by CenterNet #394

TakuyaYashima opened this issue Aug 29, 2023 · 2 comments

Comments

@TakuyaYashima
Copy link
Contributor

We got a question in CenterNet Colab demo tutorial in Youtube.

Hi, thanks for the video. This really good.
How do I run an inference for a set of images and get the prediction results saved?

@TakuyaYashima
Copy link
Contributor Author

Here's one way for that.

  1. Run the cells until where you download the pretrained weight.

  2. Instead of uploading one single image, make directories for input and output images first.

    !mkdir inputs && mkdir outputs
    
  3. Upload images of interest via Colaboratory UI or use files.upload() for multiple times and save them in inputs.

  4. Import some packages.

    import os
    import shutil
    import subprocess
    
  5. Run the script below.

    for i, image in enumerate(os.listdir("inputs")):
        if os.path.splitext(image)[1] not in ('.jpg', '.jpeg', '.png', '.webp'):
            continue
    
        cmd = ["python", "src/demo.py", "ctdet",
               "--dataset", dataset,
               "--arch", architecture,
               "--num_layers", str(num_layer),
               "--trained_model_path", param_path,
               "--demo", "inputs/" + image,
               "--gpus", "0",
               "--debug", "1",
               "--save_dir", "outputs"]
        _ = subprocess.run(cmd)
        shutil.move("outputs/ctdet.jpg",
                    f"outputs/{os.path.splitext(image)[0]}.jpg")
    
  6. You should find the images with anchor boxes in outputs. You can download them by Colaboratory UI.

@TakuyaYashima
Copy link
Contributor Author

Also I found that currently the Colab demo does not work as is.
--checkpoint is obsolete and that must be changed to --trained_model_path probably due to this commit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant