question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Calling Yolact from another Python file

See original GitHub issue

Hi @dbolya, Thanks again for such a useful model. I am trying to use yolact inside another file and I will use its outputs in terms of masks, bounding-boxes, confidence rates and classes. But it gives errors when I import yolact.eval --> ImportError: cannot import name 'Yolact' If I import yolact, there is no error. If I from yolact import eval --> ImportError: cannot import name 'Yolact', it gives the same error. After import yolact without no errors, I type yolact and it gives <module 'yolact' (namespace)>. But if I import another lib, it shows the path to that. How can I call eval.py from another python file and use its outputs? By the way my config is python 3.6, pytorch 1.0.1, cuda 9.0…

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:12 (2 by maintainers)

github_iconTop GitHub Comments

7reactions
dbolyacommented, Dec 19, 2019

What does your final structure look like? It sounds like you’re importing yolact.py not importing from the yolact directory. Though that’s actually what you want (importing yolact.py, that is).

Here’s the rough procedure:

import torch
import cv2 # Optional, see below

from yolact import Yolact
from data import set_cfg
from utils.augmentations import FastBaseTransform
from layers.output_utils import postprocess

##### Setup #####

# CUDA setup, I should really just replace all Tensor initializations but I'm in too deep at this point
torch.backends.cudnn.fastest = True
torch.set_default_tensor_type('torch.cuda.FloatTensor')

# Use whichever config you want here.
set_cfg('yolact_base_config')

net = Yolact().cuda()
net.load_weights('path/to/weight/file')
net.eval()

transform = FastBaseTransform()

##### Now to use ######

# Get your image from somewhere (BGR format, [0, 255], numpy)
img = cv2.imread('path/to/image')
h, w, _ = img.shape

batch = transform(torch.from_numpy(img).cuda().float()[None, ...])
preds = net(batch)

# You can modify the score threshold to your liking
classes, scores, boxes, masks = postprocess(preds , w, h, score_threshold=0.15)

Sorry for the number of lines of code necessary to do this. I should probably make an example script and put it on the readme or something. (Also this code is untested, if there are any bugs lmk).

2reactions
kre-kacommented, Apr 14, 2020

@zyxdb

Hey, I have a similar problem: AttributeError: ‘Config’ object has no attribute ‘mask_proto_debug’

I want to know what you said “necessary paths” and “current directory”,I only see two places in the code where I need to fill the path,(weights and img)

For a lack of better solution (or rather inability to find one), I just commented calling mask_proto_debug out in output_utils.py line 63:

#if cfg.mask_proto_debug:
        #    np.save('scripts/proto.npy', proto_data.cpu().numpy())

“Fixed” the problem without any devastating consequences (for now)

Read more comments on GitHub >

github_iconTop Results From Across the Web

python - How to save information about the result of instance ...
To save the classes and scores as a csv file: ... I think it's being called 3 times from different regions in eval.py....
Read more >
YOLACT++ Instance Segmentation (Google Colab Tutorial)
Learn the basics of YOLACT ++ and try it out in a free Google Colab notebook. Tutorial: https://www.immersivelimit.com/tutori... … Show more.
Read more >
Converting a PyTorch YOLACT Model
Before converting the model, create a patch file for the repository. ... export to ONNX --- eval.py | 5 ++++- utils/augmentations.py | 7...
Read more >
Files · main · Hee Joon Yoon / yoloact - GitLab
In order to use YOLACT++, make sure you compile the DCNv2 code. ... Process an image and save it to another file. python...
Read more >
How to train YOLACT: Real-time instance segmentation with ...
For the dataset configuration, open the yolact/data/config.py file and go to the “DATASETS” section. Create a copy from dataset_base and ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found