At awesome-panel.org i’m running the Facebook DE:TR: app.
After starting to
pn.serve with num_procs=4 my app has started crashing when I or a user start awesome-panel.org and navigate to the DE:TR: app.
The first time I go to the DE:TR: it loads fast, second time slower and third or fourth time it does not respond.
My hypothesis is that it is because I have some code I run when the DE:TR: model module is imported . I.e. it’s run once before I
pn.serve my app.
# Load model print("Loading DETR model") DEVICE = torch.device("cuda" if torch.cuda.is_available() else "cpu") detr = torch.hub.load("facebookresearch/detr", "detr_resnet50", pretrained=True) detr.eval().to(DEVICE) # standard PyTorch mean-std input image normalization transform = T.Compose( [T.Resize(500), T.ToTensor(), T.Normalize([0.485, 0.456, 0.406], [0.229, 0.224, 0.225])] ) print("Loading DETR model...DONE")
transform is then available to and shared across all sessions.
I do this because the code is slow and I would like to avoid having the user wait each time he/ she navigates to the page.
HOW DO I FIX THIS? DO I NEED TO LOAD THESE FOR EACH USER/ SESSION? Or can I safely load or share these in some way? How?
The DE:TR: app can be found here https://github.com/MarcSkovMadsen/awesome-panel/tree/1d0be4267a874463be5edee60cde5c4aa94d7226/application/pages/detr. The python code above is in the
app.py file can be found here https://github.com/MarcSkovMadsen/awesome-panel/blob/1d0be4267a874463be5edee60cde5c4aa94d7226/app.py