Giter Site home page Giter Site logo

tanveer-hussain / efficientsod Goto Github PK

View Code? Open in Web Editor NEW
20.0 3.0 3.0 49.45 MB

This research is based on efficient saliency detection using deformable convolutions.

License: Apache License 2.0

Python 71.16% MATLAB 28.84%
saliency sod saliency-detection saliency-prediction salient-object-detection dense-convolutions

efficientsod's Issues

terminating async callback

I've tried to run your model on webcam with this code:

import torch
from torchvision import transforms as T
from PIL import Image
import os
import numpy as np
import cv2
import timeit


# datasets = SIP  , DUT-RGBD  , NLPR  , NJU2K
model_path = os.path.join('DDNet_500Model.pt')
model = torch.load(model_path)
model.eval()
kernel = np.ones((5,5), np.uint8)

def preprocess_image(img):
    transform = T.Compose([T.ToPILImage(),T.Resize((224, 224)), T.ToTensor()])
    x = transform(img)
    x = torch.unsqueeze(x, 0)
    x = x.cuda(0)
    return x

def predictions(img):

    x = preprocess_image(img)
    start_time = timeit.default_timer()
    print(x.shape)
    output = model(x)
    output = torch.squeeze(output, 0)

    output = output.detach().cpu().numpy()
    output = output.dot(255)
    output *= output.max()/255.0
    # print (max(output))
    # output = cv2.erode(output, kernel, iterations=2)
    # output = cv2.dilate(output, kernel, iterations=1)
    return output


def test_video():
    cam = cv2.VideoCapture(0)
    cam.set(cv2.CAP_PROP_FRAME_WIDTH,480);
    cam.set(cv2.CAP_PROP_FRAME_HEIGHT,480);
    while True:
        ok, img = cam.read()
        # img = cv2.resize(img, (640, 480))
        img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
        output = predictions(img)
        output = np.transpose(output, (1, 2, 0))
        cv2.imshow('Mask', output)
        cv2.waitKey(10)


if __name__ == "__main__":
    test_video()

but faced with this error:

Traceback (most recent call last):
  File "demo.py", line 59, in <module>
    test_video()
  File "demo.py", line 48, in test_video
    output = predictions(img)
  File "demo.py", line 28, in predictions
    output = model(x)
  File "C:\Users\NoteBook TANDIS\AppData\Local\Programs\Python\Python37\lib\site-packages\torch\nn\modules\module.py", line 1051, in _call_impl
    return forward_call(*input, **kwargs)
  File "D:\Projects\Src\EfficientSOD-main\ModelNetworks\BaseNetwork_3.py", line 55, in forward
    x = self.deform3(x)
  File "C:\Users\NoteBook TANDIS\AppData\Local\Programs\Python\Python37\lib\site-packages\torch\nn\modules\module.py", line 1051, in _call_impl
    return forward_call(*input, **kwargs)
  File "D:\Projects\Src\EfficientSOD-main\deformable_conv.py", line 34, in forward
    offset = self.p_conv(x)
  File "C:\Users\NoteBook TANDIS\AppData\Local\Programs\Python\Python37\lib\site-packages\torch\nn\modules\module.py", line 1071, in _call_impl
    result = forward_call(*input, **kwargs)
  File "C:\Users\NoteBook TANDIS\AppData\Local\Programs\Python\Python37\lib\site-packages\torch\nn\modules\conv.py", line 443, in forward
    return self._conv_forward(input, self.weight, self.bias)
  File "C:\Users\NoteBook TANDIS\AppData\Local\Programs\Python\Python37\lib\site-packages\torch\nn\modules\conv.py", line 440, in _conv_forward
    self.padding, self.dilation, self.groups)
RuntimeError: Given groups=1, weight of size [18, 128, 3, 3], expected input[1, 256, 28, 28] to have 128 channels, but got 256 channels instead
[ WARN:0] global C:\Users\runneradmin\AppData\Local\Temp\pip-req-build-_xlv4eex\opencv\modules\videoio\src\cap_msmf.cpp (438) `anonymous-namespace'::SourceReaderCB::~SourceReaderCB terminating async callback

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.