Git Product home page Git Product logo

sairajk / pytorch-pyramid-feature-attention-network-for-saliency-detection Goto Github PK

View Code? Open in Web Editor NEW
172.0 3.0 46.0 1.2 MB

PyTorch implementation of the CVPR 2019 paper “Pyramid Feature Attention Network for Saliency Detection”

License: GNU General Public License v3.0

Python 100.00%
saliency-detection salient-object-detection pytorch-implementation pytorch python3 cvpr2019 pretrained-models pretrained attention edge-loss

pytorch-pyramid-feature-attention-network-for-saliency-detection's People

Contributors

sairajk avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

pytorch-pyramid-feature-attention-network-for-saliency-detection's Issues

a little wrong~

      torch.save(mod_chkpt, self.model_path + 'weights/best-model_epoch-{:03}_mae-{:.4f}_loss-{:.4f}.pth'.format(epoch, best_test_mae, te_avg_loss))
     while
     self.model_path = args.base_save_path + '/alph-{}_wbce_w0-{}_w1-{}'.format(str(self.alpha_sal), str(self.wbce_w0), str(self.wbce_w1))
     you are supposed to plus a '/'  in   self.model_path = args.base_save_path + '/alph-{}_wbce_w0-{}_w1-{}/'.

Pre-trained model

Is it possible to provide Your pre-trained model? "best_epoch-138_acc-0.9107_loss-0.1300.pt"
Did You trained it on DUTS-TR?

Problem with inference.py

Hi! I did run inference.py. However, I got this error when I run this code:

E:\pro1\Scripts\python.exe E:/Research/PyTorch-Pyramid-Feature-Attention-Network-for-Saliency-Detection/inference.py
  0%|          | 0/1 [00:01<?, ?it/s]
Traceback (most recent call last):
  File "E:/Research/PyTorch-Pyramid-Feature-Attention-Network-for-Saliency-Detection/inference.py", line 104, in <module>
    calculate_mae(rt_args)
  File "E:/Research/PyTorch-Pyramid-Feature-Attention-Network-for-Saliency-Detection/inference.py", line 91, in calculate_mae
    for batch_idx, (inp_imgs, gt_masks) in enumerate(tqdm.tqdm(test_dataloader), start=1):
  File "E:\pro1\lib\site-packages\tqdm\std.py", line 1127, in __iter__
    for obj in iterable:
  File "E:\pro1\lib\site-packages\torch\utils\data\dataloader.py", line 345, in __next__
    data = self._next_data()
  File "E:\pro1\lib\site-packages\torch\utils\data\dataloader.py", line 856, in _next_data
    return self._process_data(data)
  File "E:\pro1\lib\site-packages\torch\utils\data\dataloader.py", line 881, in _process_data
    data.reraise()
  File "E:\pro1\lib\site-packages\torch\_utils.py", line 394, in reraise
    raise self.exc_type(msg)
IndexError: Caught IndexError in DataLoader worker process 0.
Original Traceback (most recent call last):
  File "E:\pro1\lib\site-packages\torch\utils\data\_utils\worker.py", line 178, in _worker_loop
    data = fetcher.fetch(index)
  File "E:\pro1\lib\site-packages\torch\utils\data\_utils\fetch.py", line 44, in fetch
    data = [self.dataset[idx] for idx in possibly_batched_index]
  File "E:\pro1\lib\site-packages\torch\utils\data\_utils\fetch.py", line 44, in <listcomp>
    data = [self.dataset[idx] for idx in possibly_batched_index]
  File "E:\Research\PyTorch-Pyramid-Feature-Attention-Network-for-Saliency-Detection\src\dataloader.py", line 163, in __getitem__
    mask_img = cv2.imread(self.out_files[idx], 0)
IndexError: list index out of range


Process finished with exit code 1

You provide initial 3 images in ./data/DUTS/DUTS-TE/DUTS-TE-Image. I just add two more my own images in this folder and then run inference.py. It seems the number in masks and images folder should be the same. I don't know why.

Would you please help me with this? Thank you so much for your help!

Output images

Hi,
I am getting the output images as grayish images rather than black and white. Could you help me what's the problem and how to deal with it?

Question about RetinaNet FPN implementation

Hello,

I am working with image detection tasks with RetinaNet.

I would like to know if is possible join this fpn implementation with RetinaNet.

Basically I want train this FPN implementation with my train dataset, save the weights and use them to detect the objects in my test dataset.

TypeError: unsupported operand type(s) for %: 'int' and 'NoneType'

Hi,
I got the problem, I can begin trainging the code. But while run epoch=2, it show this problem and stop to train.

File "train.py", line 212, in
trainer.train()
File "train.py", line 122, in train
if epoch % self.test_interval == 0 or epoch % self.save_interval == 0:
TypeError: unsupported operand type(s) for %: 'int' and 'NoneType'

Data/DUTS-TE-Mask

Hi Sairajk! Thank you so much for your amazing code! When I use this code I have some problems.

I run the inference.py. However, the inference images don't have mask-images.

I put my own image into DUTS-TE-Image and use the downloaded masks file. I found that I can get results but the number of DUTS-TE-Image should be the same as masks file.

May I ask do you have any solutions for those who don't have ground-truth masks image?
Thank you so much!!!

Training set Images

Hi,
Thanks for the wonderful code. I wanted to ask that is there any way to create the training set images? Like how can we create salient images that can be fed into our training model?

Question about Image size and ratio

Hi! Thank you so much for this amazing work. It's quite helpful. I met a problem right now and need your help. I want to resize the image and make it a rectangle.
Here

parser.add_argument('--img_size', default=256, help='Image size to be used', [type=int)](https://github.com/sairajk/PyTorch-Pyramid-Feature-Attention-Network-for-Saliency-Detection/blob/master/inference.py#L23)

I'm wondering what's the largest size can this number be? I changed it to 1280 but there seem problems. And then I use 640 and I found the saliency area changed comparing with 256.

I'm also wondering whether I can change the output image as a rectangle. (16:9) ratio.

I don't want to resize by some image processing tools because I think it will change the saliency value for each pixel and destroy the one-to-one corresponding pixel relationship.

I'm wondering do we have solution inside the code.

Thank you so much!

File name of the out put images

Hi! I'm using this model on my own dataset. I met the problem of the order of the image.
I basically run interface.py to get my output.

The input folder of my file looks like this:
image

The name is from 0 to 504.
But when the python program reads the file, it will reorder the image and disorganize the images. Windows usually read like 000, 001,002...100,101,102....

I notice that you use InfDataloader. But I'm wondering whether I can use some API to get the name. save it like line 68-76:
image

The result image that I got doesn't have the same order as my input. For example, input 0.png is output 187.png.

I'm wondering how to keep the order and file name as the input. Would you please help me with this?
I'm not familiar with pytorch.

Thank you so so so much!!!!!!!

Problem with image augmentation

Test image augmentation functions

inp_img = cv2.imread('/content/drive/My Drive/DUTS-TE/DUTS-TE-Image/ILSVRC2012_test_00000003.jpg')
out_img = cv2.imread('/content/drive/My Drive/DUTS-TE/DUTS-TE-Mask/ILSVRC2012_test_00000003.png', -1)
# inp_img = inp_img.astype('float32')
out_img = out_img.astype('float32')
out_img = out_img / 255.0

cv2_imshow(inp_img)
cv2_imshow(out_img)

print('\nImage shapes before processing :', inp_img.shape, out_img.shape)
x, y = random_crop_flip(inp_img, out_img)
x, y = random_rotate(x, y)
x = random_brightness(x)
x, y = pad_resize_image(x, y, target_size=256

# x now contains float values, so either round-off the values or convert the pixel range to 0-1.
x = x / 255.0
print('Image shapes after processing :', x.shape, y.shape)

cv2_imshow(x)
cv2_imshow(y)
cv2.waitKey(0)

After using that function I have:

dog1
dog2

some question

When I run the train file, there is a ValueError: too many values to unpack (expected 2) error
in the pred_masks, ca_act_reg = self.model(inp_imgs) statement.

I hope you can help. @sairajk

Error connect ECONNREFUSED 127.0.0.1:13246

Hi,Sairajk.
Your work is helpful to me.
However, the following error pops up during training the model.Thus, the saved model does not achieve the desired effect.
connect ECONNREFUSED报错
Based on your experience, what could be the reason for this?

epoch

When training starts an epoch, it stops ,

Error while using Google Colab

ValueError Traceback (most recent call last)

in ()
228 test_data = SODLoader(mode='test', augment_data=False, target_size=img_size)
229
--> 230 train_dataloader = DataLoader(train_data, batch_size=bs, shuffle=True, num_workers=1)
231 test_dataloader = DataLoader(test_data, batch_size=bs, shuffle=False, num_workers=2)
232

92 if not isinstance(self.num_samples, int) or self.num_samples <= 0:
93 raise ValueError("num_samples should be a positive integer "
---> 94 "value, but got num_samples={}".format(self.num_samples))
95
96 @Property

ValueError: num_samples should be a positive integer value, but got num_samples=0

What should I do with that?

Implementation different from the paper

Thanks for your code!
After reading your code and the paper, I found some differece.
image
image
In your code, the SA module process the conv_345_feats. However, in the original paper, the SA module process low-level features. @sairajk

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.