Error while setting dropout value in Efficenet pytroch from the torch vision library

username: akshay_23
cooked: <p>When the run the following code I get this error</p>
<pre><code class="lang-auto">model = torchvision_models.efficientnet_b0(stochastic_depth_prob=0.8,num_classes=2,dropout=0.5)
</code></pre>
<hr>
<pre><code class="lang-auto">TypeError                                 Traceback (most recent call last)
Input In [144], in &lt;cell line: 1&gt;()
----&gt; 1 model = torchvision_models.efficientnet_b0(stochastic_depth_prob=0.8,num_classes=2,dropout=0.5)

File ~/miniconda3/lib/python3.9/site-packages/torchvision/models/_utils.py:142, in kwonly_to_pos_or_kw.&lt;locals&gt;.wrapper(*args, **kwargs)
    135     warnings.warn(
    136         f"Using {sequence_to_str(tuple(keyword_only_kwargs.keys()), separate_last='and ')} as positional "
    137         f"parameter(s) is deprecated since 0.13 and will be removed in 0.15. Please use keyword parameter(s) "
    138         f"instead."
    139     )
    140     kwargs.update(keyword_only_kwargs)
--&gt; 142 return fn(*args, **kwargs)

File ~/miniconda3/lib/python3.9/site-packages/torchvision/models/_utils.py:228, in handle_legacy_interface.&lt;locals&gt;.outer_wrapper.&lt;locals&gt;.inner_wrapper(*args, **kwargs)
    225     del kwargs[pretrained_param]
    226     kwargs[weights_param] = default_weights_arg
--&gt; 228 return builder(*args, **kwargs)

File ~/miniconda3/lib/python3.9/site-packages/torchvision/models/efficientnet.py:757, in efficientnet_b0(weights, progress, **kwargs)
    754 weights = EfficientNet_B0_Weights.verify(weights)
    756 inverted_residual_setting, last_channel = _efficientnet_conf("efficientnet_b0", width_mult=1.0, depth_mult=1.0)
--&gt; 757 return _efficientnet(inverted_residual_setting, 0.2, last_channel, weights, progress, **kwargs)

TypeError: _efficientnet() got multiple values for argument 'dropout'
</code></pre>
<p>I checked the documentation(<a href="https://pytorch.org/vision/main/models/generated/torchvision.models.efficientnet_b0.html#torchvision.models.efficientnet_b0" class="inline-onebox" rel="noopener nofollow ugc">efficientnet_b0 — Torchvision main documentation</a>, <a href="https://github.com/pytorch/vision/blob/main/torchvision/models/efficientnet.py" class="inline-onebox" rel="noopener nofollow ugc">vision/efficientnet.py at main · pytorch/vision · GitHub</a>) and this is what it states</p>
<pre><code>    Args:
        inverted_residual_setting (Sequence[Union[MBConvConfig, FusedMBConvConfig]]): Network structure
        dropout (float): The droupout probability
        stochastic_depth_prob (float): The stochastic depth probability
        num_classes (int): Number of classes
        norm_layer (Optional[Callable[..., nn.Module]]): Module specifying the normalization layer to use
        last_channel (int): The number of channels on the penultimate layer
    """
</code></pre>

username: ptrblck
cooked: <p>Based on <a href="https://github.com/pytorch/vision/blob/677fc939b21a8893f07db4c1f90482b648b6573f/torchvision/models/efficientnet.py#L782">this line of code</a> it seems the <code>dropout</code> value is hard-coded to <code>0.2</code>:</p>
<pre><code class="lang-python">return _efficientnet(inverted_residual_setting, 0.2, last_channel, weights, progress, **kwargs)
</code></pre>
<p>which is the reason the error is raised.</p>
<p>CC <a class="mention" href="/u/pmeier">@pmeier</a> for viz in case this is a mistake.</p>

username: pmeier
cooked: <p>Hey <a class="mention" href="/u/akshay_23">@akshay_23</a> and thanks for the report. I took the liberty and open an issue on TorchVision’s issue tracker “in your name”: <a href="https://github.com/pytorch/vision/issues/7029" class="inline-onebox" rel="noopener nofollow ugc">EfficientNet documentation is (probably) misleading · Issue #7029 · pytorch/vision · GitHub</a>.</p>

username: akshay_23
cooked: <p>Thanks <a class="mention" href="/u/pmeier">@pmeier</a> for opening the issue , I feel it could be a bug too and it requires a simple fix or they deliberately hard coded the values for some reason, will look into it</p>

username: pmeier
cooked: <p>It was deemed a bug and was fixed in <a href="https://github.com/pytorch/vision/pull/7031" class="inline-onebox" rel="noopener nofollow ugc">Allow dropout overwrites on EfficientNet by datumbox · Pull Request #7031 · pytorch/vision · GitHub</a>. If you use the the nightly version of <code>torchvision</code>, you should have access to the fix in a few hours. Otherwise you’ll have to wait for the next release in Q1 of 2023.</p>

username: akshay_23
cooked: <p>sure thanks , currently I can set it using<br>
<code>model.classifier[0] = torch.nn.Dropout(p=self.dropout_p, inplace=True)</code><br>
so not much of a hassle , I initially thought there was something wrong with the way I coded it but it has been clarified now , would check out the nightly version of <code>torchvision</code>.<br>
Thanks for the quick response</p>