lutzroeder / netron

Visualizer for neural network, deep learning and machine learning models
https://netron.app
MIT License
28.17k stars 2.79k forks source link

Darknet: deconvolution output shape #1396

Closed Flova closed 3 days ago

Flova commented 4 days ago

I expect a deconvolution to increase the resolution of the feature map, but for Darknet cfg files Netron handles the deconvolution the same way it handles the convolution:

https://github.com/lutzroeder/netron/blob/f59afb65204fceab34023ee33162db874ecb5416/source/darknet.js#L260

And the output resolution of the convolutional layer in Netron is computed like this: https://github.com/lutzroeder/netron/blob/f59afb65204fceab34023ee33162db874ecb5416/source/darknet.js#L127

while Darknet computes the deconvolution like this:

https://github.com/pjreddie/darknet/blob/f6afaabcdf85f77e7aff2ec55c020c0e297c77f9/src/deconvolutional_layer.c#L67C5-L67C55

l.out_h = (l.h - 1) * l.stride + l.size - 2*l.pad;

Current behavior:

image

Expected Behavior:

image

Steps to Reproduce:

  1. Create cfg file with deconv layer
  2. Observe the changes to the feature map size

Please attach or link model files to reproduce the issue.

Example cfg with deconvolution:

[net] # Testing #batch=1 #subdivisions=1 # Training batch=64 subdivisions=4 width=416 height=416 channels=3 momentum=0.9 decay=0.0005 angle=0 saturation = 1.5 exposure = 1.5 hue=.1 learning_rate=0.0001 burn_in=100 max_batches = 4000 policy=steps steps=50000,60000 scales=.1,.1 [convolutional] batch_normalize=1 filters=32 size=3 stride=2 pad=1 activation=leaky [convolutional] batch_normalize=1 filters=64 size=3 stride=2 pad=1 activation=leaky [convolutional] batch_normalize=1 filters=64 size=3 stride=1 pad=1 activation=leaky [route] layers=-1 groups=2 group_id=1 [convolutional] batch_normalize=1 filters=32 size=3 stride=1 pad=1 activation=leaky [convolutional] batch_normalize=1 filters=32 size=3 stride=1 pad=1 activation=leaky [route] layers = -1,-2 [convolutional] batch_normalize=1 filters=64 size=1 stride=1 pad=1 activation=leaky [route] layers = -6,-1 [maxpool] size=2 stride=2 [convolutional] batch_normalize=1 filters=128 size=3 stride=1 pad=1 activation=leaky [route] layers=-1 groups=2 group_id=1 [convolutional] batch_normalize=1 filters=64 size=3 stride=1 pad=1 activation=leaky [convolutional] batch_normalize=1 filters=64 size=3 stride=1 pad=1 activation=leaky [route] layers = -1,-2 [convolutional] batch_normalize=1 filters=128 size=1 stride=1 pad=1 activation=leaky [route] layers = -6,-1 [maxpool] size=2 stride=2 [convolutional] batch_normalize=1 filters=256 size=3 stride=1 pad=1 activation=leaky [route] layers=-1 groups=2 group_id=1 [convolutional] batch_normalize=1 filters=128 size=3 stride=1 pad=1 activation=leaky [convolutional] batch_normalize=1 filters=128 size=3 stride=1 pad=1 activation=leaky [route] layers = -1,-2 [convolutional] batch_normalize=1 filters=256 size=1 stride=1 pad=1 activation=leaky [route] layers = -6,-1 [maxpool] size=2 stride=2 [convolutional] batch_normalize=1 filters=512 size=3 stride=1 pad=1 activation=leaky ########### [convolutional] batch_normalize=1 filters=256 size=1 stride=1 pad=1 activation=leaky [convolutional] batch_normalize=1 filters=512 size=3 stride=1 pad=1 activation=leaky [convolutional] size=1 stride=1 pad=1 filters=8 activation=linear [yolo] mask = 0 anchors = 100, 100 classes=3 num=1 jitter=.3 ignore_thresh = .7 truth_thresh = 1 random=1 [route] layers = -4 [convolutional] batch_normalize=1 filters=128 size=1 stride=1 pad=1 activation=leaky [upsample] stride=2 [route] layers = -1, 24 [convolutional] batch_normalize=1 filters=256 size=3 stride=1 pad=1 activation=leaky [convolutional] size=1 stride=1 pad=1 filters=8 activation=linear [yolo] mask = 0 anchors = 100, 100 classes=3 num=1 jitter=.3 ignore_thresh = .7 truth_thresh = 1 random=1 [route] layers = 18 [deconvolutional] batch_normalize=1 filters=128 size=2 stride=2 pad=0 activation=leaky [route] layers = -1, 10 [convolutional] batch_normalize=1 filters=64 size=1 stride=1 pad=1 activation=leaky [convolutional] batch_normalize=1 filters=64 size=3 stride=1 pad=1 activation=leaky [upsample] stride=2 [route] layers = -1, 2 [convolutional] batch_normalize=1 filters=32 size=1 stride=1 pad=1 activation=leaky [convolutional] batch_normalize=1 filters=32 size=3 stride=1 pad=1 activation=leaky [upsample] stride=2 [route] layers = -1, 0 [convolutional] batch_normalize=1 filters=16 size=1 stride=1 pad=1 activation=leaky [convolutional] batch_normalize=1 filters=16 size=3 stride=1 pad=1 activation=leaky [upsample] stride=2 [convolutional] batch_normalize=1 filters=16 size=3 stride=1 pad=1 activation=leaky [convolutional] batch_normalize=1 filters=3 size=1 stride=1 pad=1 activation=linear [seg] classes=3
Flova commented 1 day ago

Thanks!