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

Better errors & faster Replicate predictions #36

Merged
merged 4 commits into from
Sep 11, 2021

Conversation

bfirsh
Copy link
Contributor

@bfirsh bfirsh commented Sep 10, 2021

Hello again @yuval-alaluf :)

This pull request does a few little things:

  • Moves loading model into setup() to make running predictions much faster/more efficient (we noticed this during the high traffic yesterday!)
  • Adds a better error when the face couldn't be aligned (before is was something about shape being undefined, and it looked broken)
  • Scripts to download weights / face landmarks to right place

If you run cog push after merging and pulling, it'll update the version on Replicate. 😄

@yuval-alaluf
Copy link
Owner

Hi @bfirsh!
The changes look good so I'm merging your changes. I'm interested in seeing how these changes will affect the response time on Replicate. I'll also try to make similar changes to my ReStyle demo :)

@yuval-alaluf yuval-alaluf merged commit 8d1c4b3 into yuval-alaluf:master Sep 11, 2021
@yuval-alaluf
Copy link
Owner

Hey @bfirsh ,
Although I merged your update, I am playing around with further optimizing the predict function. Currently, we are still performing the following for every predict call:

SAM/predict.py

Lines 45 to 48 in 8d1c4b3

net = pSp(self.opts)
net.eval()
if torch.cuda.is_available():
net.cuda()

Although this takes only a few seconds, since it's always the same net each time I thought about moving this to the setup function so we'll have something like:

        model_path = "pretrained_models/sam_ffhq_aging.pt"
        ckpt = torch.load(model_path, map_location="cpu")

        opts = ckpt["opts"]
        opts["checkpoint_path"] = model_path
        opts["device"] = "cuda" if torch.cuda.is_available() else "cpu"

        self.shape_predictor = dlib.shape_predictor("shape_predictor_68_face_landmarks.dat")

        self.opts = Namespace(**opts)
        self.net = pSp(self.opts)
        self.net.eval()
        if torch.cuda.is_available():
            self.net.cuda()

But if I do this, I get a very weird behavior on Replicate:
Screen Shot 2021-09-11 at 14 26 51
It seems like it is stuck in a loop loading the model.
Do you know why something like this could happen?

@yuval-alaluf
Copy link
Owner

Also, when I run cog predict locally, this behavior doesn't occur. So I'm wondering if this is something that is happening "behind the scenes" that I simply can't see 🤔

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

Successfully merging this pull request may close these issues.

2 participants