xavysp / DexiNed

DexiNed: Dense EXtreme Inception Network for Edge Detection
MIT License
737 stars 156 forks source link

Curious: Why do _DenseLayer and _DenseBlock extend nn.Sequential instead of nn.Module? #15

Open stephenwithav opened 4 years ago

stephenwithav commented 4 years ago

Is there a benefit to extending nn.Sequential instead of, e.g.:

class _DenseBlock(nn.Module):
    def __init__(self, num_layers, input_features, out_features):
        super(_DenseBlock, self).__init__()
        for i in range(num_layers):
            layer = nn.Sequential(['conv/bn/relu/conv/bn'])  # Swapped for _DenseLayer
            self.add_module('denselayer%d' % (i + 1), layer)
            input_features = out_features
xavysp commented 4 years ago

Great question, I am a beginner in Pytorch, @edgarriba could you help us. He coded most of the architecture, later on, I modified just a little bit, but not this part. By the by I am courious now :)

stephenwithav commented 4 years ago

I'm new to PyTorch, as well. I'm going to experiment today to see if it makes a difference.

stephenwithav commented 4 years ago

SqueezeNet shows the idiomatic way to do this, so I'll submit a PR later today that mimics its structure.

EDIT: Or tomorrow... depending on when MBIPED finishes. :)

xavysp commented 4 years ago

SqueezeNet shows the idiomatic way to do this, so I'll submit a PR later today that mimics its structure.

EDIT: Or tomorrow... depending on when MBIPED finishes. :)

Hi @stephenwithav thanks for the help. I don't follow you "depending on when MBIPED finishes. :)"

stephenwithav commented 4 years ago

I'm retraining MBIPED from scratch using CPU only for the first time, so I don't know when it'll finish.

Then I'll retrain the modified DexiNed-PyTorch on CPU. (I have an old AMD Radeon GPU, so no support in TF or PyTorch.)

I may run it in Colab tomorrow.

And you're welcome. I'm happy to contribute as I think this may help with my primary project.

stephenwithav commented 4 years ago

MBIPED complete.

DexiNed-PyTorch training has begun.

How long did this take with a GPU?

stephenwithav commented 4 years ago

300 images in 9 hours on CPU. Time for Colab. :)

xavysp commented 4 years ago

MBIPED complete.

DexiNed-PyTorch training has begun.

How long did this take with a GPU?

~2 days with a titan X

xavysp commented 4 years ago

300 images in 9 hours on CPU. Time for Colab. :)

sure

stephenwithav commented 4 years ago

2 days? Yikes!

I'm trying to get permission from an artist to create a new dataset of 400+ images to use this on.

stephenwithav commented 4 years ago

Running final test on the rewrite now.

Will you be able to train the new model on the Titan X?

If not, I'll look at the available options.

xavysp commented 4 years ago

Running final test on the rewrite now.

Will you be able to train the new model on the Titan X?

If not, I'll look at the available options.

sorry, just give me a couple of days, I have to finish some staff here cheers,

stephenwithav commented 4 years ago

Will do. Thanks!

(Finishing up the Keras version now.)

xavysp commented 4 years ago

Will do. Thanks!

(Finishing up the Keras version now.)

Really? finishing the Keras version, wow if you don't mind, I would like to see the script I will save cautiously

Cheers1

Xavier

xavysp commented 4 years ago

Running final test on the rewrite now.

Will you be able to train the new model on the Titan X?

If not, I'll look at the available options.

Sorry, now I am training the native version of DexiNed, using the tf.nn.conv2d instead of layers.conv2 :(. But I will do after finishing this

stephenwithav commented 4 years ago

A PR will definitely be submitted with the Keras version when it's complete.

Translating block_cat is giving me some trouble at the moment, but the obstacle doesn't seem impossible. (torch.cat vs. tf.concat)

stephenwithav commented 4 years ago

I took a week away from this to let me return with a fresh perspective.

Does the paper mention why DexiNed includes img = img.transpose((2,0,1)) in testDataset.transform and BipedMyDataset.transform?

stephenwithav commented 4 years ago

Got it. img.transpose((2,0,1)) just puts the channels first, as required by PyTorch.

xavysp commented 4 years ago

I took a week away from this to let me return with a fresh perspective.

Does the paper mention why DexiNed includes img = img.transpose((2,0,1)) in testDataset.transform and BipedMyDataset.transform?

Hi good to have you back :) the paper is based on the DexiNed TensorFlow version. By the way, this is not a big deal you know TF works BxHxWxC and PyTorch BxCxHxW that is why we use in Pytorch img.transpose.

xavysp commented 4 years ago

Got it. img.transpose((2,0,1)) just puts the channels first, as required by PyTorch.

sorry I did not see this :)

stephenwithav commented 4 years ago

Hi good to have you back :) the paper is based on the DexiNed TensorFlow version. By the way, this is not a big deal you know TF works BxHxWxC and PyTorch BxCxHxW that is why we use in Pytorch img.transpose.

I'll be here for a bit. :)

As long as this remains the best edge detection method, I'll be here.

When the updated version of DexiNed is released, I'll update the TF to match it.

xavysp commented 4 years ago

Hi good to have you back :) the paper is based on the DexiNed TensorFlow version. By the way, this is not a big deal you know TF works BxHxWxC and PyTorch BxCxHxW that is why we use in Pytorch img.transpose.

I'll be here for a bit. :)

As long as this remains the best edge detection method, I'll be here.

When the updated version of DexiNed is released, I'll update the TF to match it.

Hi, and good to know that. About the update, After checking the model I forget changing two conv layers settings, I need to re-train , I am delayed :( respect to DexiNed-TF2 right now I am training, whenever the quantitative evaluation is performed I will update the ripo, Thank for the model by the way.

Cheers

stephenwithav commented 4 years ago

Thanks for the update, the fixes, and the training. I look forward to testing the final model on new images.