DexiNed icon indicating copy to clipboard operation
DexiNed copied to clipboard

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

Open stephenwithav opened this issue 4 years ago • 23 comments

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

stephenwithav avatar May 12 '20 13:05 stephenwithav

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 :)

xavysp avatar May 14 '20 02:05 xavysp

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

stephenwithav avatar May 14 '20 09:05 stephenwithav

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. :)

stephenwithav avatar May 14 '20 18:05 stephenwithav

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. :)"

xavysp avatar May 14 '20 20:05 xavysp

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 avatar May 14 '20 20:05 stephenwithav

MBIPED complete.

DexiNed-PyTorch training has begun.

How long did this take with a GPU?

stephenwithav avatar May 14 '20 23:05 stephenwithav

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

stephenwithav avatar May 15 '20 10:05 stephenwithav

MBIPED complete.

DexiNed-PyTorch training has begun.

How long did this take with a GPU?

~2 days with a titan X

xavysp avatar May 15 '20 16:05 xavysp

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

sure

xavysp avatar May 15 '20 16:05 xavysp

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 avatar May 15 '20 16:05 stephenwithav

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.

stephenwithav avatar May 16 '20 15:05 stephenwithav

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,

xavysp avatar May 19 '20 15:05 xavysp

Will do. Thanks!

(Finishing up the Keras version now.)

stephenwithav avatar May 19 '20 19:05 stephenwithav

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 avatar May 21 '20 12:05 xavysp

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

xavysp avatar May 21 '20 12:05 xavysp

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 avatar May 21 '20 14:05 stephenwithav

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 avatar May 29 '20 13:05 stephenwithav

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

stephenwithav avatar May 29 '20 17:05 stephenwithav

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 avatar May 30 '20 00:05 xavysp

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

sorry I did not see this :)

xavysp avatar May 30 '20 00:05 xavysp

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.

stephenwithav avatar May 30 '20 16:05 stephenwithav

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

xavysp avatar Jun 01 '20 14:06 xavysp

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

stephenwithav avatar Jun 02 '20 20:06 stephenwithav