Giter VIP home page Giter VIP logo

pytorch-hed's Introduction

pytorch-hed

This is a personal reimplementation of Holistically-Nested Edge Detection [1] using PyTorch. Should you be making use of this work, please cite the paper accordingly. Also, make sure to adhere to the licensing terms of the authors. Should you be making use of this particular implementation, please acknowledge it appropriately [2].

Paper

For the original version of this work, please see: https://github.com/s9xie/hed
For another reimplementation based on Caffe, please see: https://github.com/zeakey/hed

usage

To run it on your own image, use the following command. Please make sure to see their paper / the code for more details.

python run.py --model bsds500 --in ./images/sample.png --out ./out.png

I am afraid that this reimplementation is not entirely true to the original Caffe version, even though it utilizes the official weights. It achieves an ODS=0.774 versus the official ODS=0.780 on the BSDS500 dataset, evaluated using this code. Please feel free to contribute to this repository by submitting issues and pull requests.

comparison

Comparison

references

[1]  @inproceedings{Xie_ICCV_2015,
         author = {Saining Xie and Zhuowen Tu},
         title = {Holistically-Nested Edge Detection},
         booktitle = {IEEE International Conference on Computer Vision},
         year = {2015}
     }
[2]  @misc{pytorch-hed,
         author = {Simon Niklaus},
         title = {A Reimplementation of {HED} Using {PyTorch}},
         year = {2018},
         howpublished = {\url{https://github.com/sniklaus/pytorch-hed}}
    }

pytorch-hed's People

Contributors

sniklaus 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  avatar  avatar  avatar

pytorch-hed's Issues

Using HED as a term of feature-based loss

Hi sniklaus,
Thanks very much for u excellent implementation.
There is a qusetion that I'd like to ask you for advice.
Have you ever used HED's feature map as a supervised term, just similar to VGG loss?
It would be greatly appreciated if you could offer me any suggestions!
Best,
Melon

problem of the pretrained model

HI ,good morning. So sorry to bother you . There are something wrong with the pretrained network as follows .

deserialized_objects[key]._set_from_file(f, offset, f_should_read_directly)
RuntimeError: unexpected EOF, expected 4922858 more bytes. The file might be corrupted.

image

PyTorch HED

Hello!

I really liked the idea of finding the edges of images with Holistically-Nested Edge Detection. But unfortunately, even on the sample.png image example, when I launch code "run.py" I have an error "option -f not recognized". I don't know how to solve this problem.

I also try to use reimplementation Pytorch Holistically-Nested Edge Detection with sample.png image example, I don’t get the same result as in the description, after running the code I get an image in gray shades and unlike contours.

I will be grateful for the answer!

BN layer

I have read some source code about many edge detection network, all of the network are without BN layer, why was that?

about pre-trained model

can you tell me how to open network-bsds500.pytorch(i.e.the file download use download.bash), i use .txt or .py the file will change to garbled。so,can you provide .pth file,or tell me how to open it?

AttributeError: 'Tensor' object has no attribute 'clip'

Hi there, it seemed that your latest commit(5ef88c3) didn't work well with PyTorch 1.6? After python run.py, I got the following error,

Traceback (most recent call last):
File "run.py", line 154, in
PIL.Image.fromarray((tenOutput.clip(0.0, 1.0).numpy().transpose(1, 2, 0)[:, :, 0] * 255.0).astype(numpy.uint8)).save(arguments_strOut)
AttributeError: 'Tensor' object has no attribute 'clip'

When I changed the clip back to clamp, it worked. Could you be so kind to provide me with any clues on this? Thanks.

How to run without CUDA?

It shows error on my laptop:
AssertionError: Torch not compiled with CUDA enabled

Is it possible to run without CUDA?

RGB Normalization problem

Hi, I noticed that in the forward function it normalizes the input as

tenBlue = (tenInput[:, 0:1, :, :] * 255.0) - 104.00698793
tenGreen = (tenInput[:, 1:2, :, :] * 255.0) - 116.66876762 
tenRed = (tenInput[:, 2:3, :, :] * 255.0) - 122.67891434

But when I noramlized it by ImageNet RGB mean[0.485, 0.456, 0.406] as follows:

tenBlue = tenInput[:, 0:1, :, :]  - 0.406
tenGreen = tenInput[:, 1:2, :, :] - 0.456
tenRed = tenInput[:, 2:3, :, :] - 0.485

The output become blurry:
out2
I feel very confused about this cause it seems to be same normalization process

model

你好,我还没有运行原代码,我想看一下这个模型的效果。
你能不能分享一下bsds500 的模型,感激不尽。

RuntimeError: shape '[1, 3, 320, 480]' is invalid for input of size 614400

Traceback (most recent call last): File "run.py", line 153, in <module> tenOutput = estimate(tenInput) File "run.py", line 145, in estimate return netNetwork(tenInput.cuda().view(1, 3, intHeight, intWidth))[0, :, :, :].cpu() RuntimeError: shape '[1, 3, 320, 480]' is invalid for input of size 614400
I tried to test my own image, but I got this error. The difference between sample.png and my own image.png is the bit depth. Mine is 32 bit depth.

I am trying to run the command "python run.py --model bsds500 --in ./images/sample.png --out ./out.png" and I am getting the error:

Traceback (most recent call last):
File "run.py", line 152, in
tenOutput = estimate(tenInput)
File "run.py", line 135, in estimate
netNetwork = Network().eval()
File "run.py", line 95, in init
self.load_state_dict({ strKey.replace('module', 'net'): tenWeight for strKey, tenWeight in torch.hub.load_state_dict_from_url(url='http://content.sniklaus.com/github/pytorch-hed/network-' + arguments_strModel + '.pytorch', file_name='hed-' + arguments_strModel).items() })
TypeError: load_state_dict_from_url() got an unexpected keyword argument 'file_name'

Training details

Could you please provide the details of training your pytorch model? Thanks!

HED: side-output

Hello! Thanks for your work on re-implement HED from image to image. It's a practical Project! Can you teach me how to get HED side-output(eg. side-output 4)? HED's output is a fuse output ,I want to compare side-output with fuse output.

F-Score is terrible for individual images

`Hello,

I took images from the BSDS dataset, and individually analyzed the F-Scores. I observed that the result is pretty bad in general, and I am not sure what I'm doing wrong. I am suspecting a bug, but I'm not confident.

Image vs ground truth:
image

HED output:
image

And of course, if the value of an individual cell is greater than 0.5, I round it off to 1 before estimating the F1 score. The image after rounding off looks like this:

image

Then, I calculate the F-Score using the following code:

Here, the gt is the groundtruth and the pred array is the prediction image from HED.

tp = np.sum(pred[np.where(pred == 1)] == gt[np.where(pred == 1)])
fp = np.sum(pred[np.where(pred == 1)] != gt[np.where(pred == 1)])
precision = tp / (tp + fp)

# recall
fn = np.sum(pred[np.where(pred == 0)] != gt[np.where(pred == 0)])
recall = tp / (tp + fn)

# f-value
fvalue = 2 * precision * recall / (precision + recall)

I get a value (F1 score) of 0.1 to 0.2.
The paper and the Github descriptions state much higher values (>0.7). Can anyone guide me regarding what could be going wrong? Since I am using the same metric and the same score, it is a little tricky.

Any help is appreciated.

How can I adjust the level of detail of the output

Hi, thank for your work! When I apply the network to some images, I found that the output is not fine-grained enough due to style gap and low resolution of source image. So how can I generate edge image with more detail? Change some hyperparameters?

problem

I want to know if this code is used for training or testing? If it is for training, why would the result be directly output?

Multiple images as input

Hello, @sniklaus Thanks for your contribution! Is there a way to generate edges from multiple images under a specific directory with your run.py? It seemed that your run.py can only process a single image as input so far. Thanks.

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.