Issues with densenet model

Hamada_Fathy: <p>i have trained a model on gpu but i want to deploy it on cpu… i got that error “AttributeError: ‘_DenseLayer’ object has no attribute ‘memory_efficient’” when i train densenet model but the inference works fine with any other pretrained model</p>

mailcorahul: <p>can you show the full traceback here? also are you saying densenet pretrained inference runs fine?</p>

Hamada_Fathy: <p>Here is the full traceback<br>
Traceback (most recent call last):<br>
File “chexpert_prediction.py”, line 227, in <br>
preds = learn.predict(orig_img)<br>
File “/home/tfradai_gmail_com/anaconda3/envs/fast_cpu/lib/python3.7/site-packages/fastai/basic_train.py”, line 37<br>
5, in predict<br>
res = self.pred_batch(batch=batch, with_dropout=with_dropout)<br>
File “/home/tfradai_gmail_com/anaconda3/envs/fast_cpu/lib/python3.7/site-packages/fastai/basic_train.py”, line 35<br>
4, in pred_batch<br>
if not with_dropout: preds = loss_batch(self.model.eval(), xb, yb, cb_handler=cb_handler)<br>
File “/home/tfradai_gmail_com/anaconda3/envs/fast_cpu/lib/python3.7/site-packages/fastai/basic_train.py”, line 26<br>
, in loss_batch<br>
out = model(*xb)<br>
File “/home/tfradai_gmail_com/anaconda3/envs/fast_cpu/lib/python3.7/site-packages/torch/nn/modules/module.py”, li<br>
ne 547, in <strong>call</strong><br>
result = self.forward(*input, **kwargs)<br>
File “/home/tfradai_gmail_com/anaconda3/envs/fast_cpu/lib/python3.7/site-packages/torch/nn/modules/container.py”,<br>
line 92, in forward<br>
input = module(input)<br>
File “/home/tfradai_gmail_com/anaconda3/envs/fast_cpu/lib/python3.7/site-packages/torch/nn/modules/module.py”, li<br>
ne 547, in <strong>call</strong><br>
result = self.forward(*input, **kwargs)<br>
File “/home/tfradai_gmail_com/anaconda3/envs/fast_cpu/lib/python3.7/site-packages/torch/nn/modules/container.py”,<br>
line 92, in forward<br>
input = module(input)<br>
File “/home/tfradai_gmail_com/anaconda3/envs/fast_cpu/lib/python3.7/site-packages/torch/nn/modules/module.py”, li<br>
ne 547, in <strong>call</strong><br>
result = self.forward(*input, **kwargs)<br>
File “/home/tfradai_gmail_com/anaconda3/envs/fast_cpu/lib/python3.7/site-packages/torch/nn/modules/container.py”,<br>
line 92, in forward<br>
input = module(input)<br>
File “/home/tfradai_gmail_com/anaconda3/envs/fast_cpu/lib/python3.7/site-packages/torch/nn/modules/module.py”, li<br>
ne 547, in <strong>call</strong><br>
result = self.forward(*input, **kwargs)<br>
File “/home/tfradai_gmail_com/anaconda3/envs/fast_cpu/lib/python3.7/site-packages/torchvision/models/densenet.py”<br>
, line 74, in forward<br>
new_features = layer(*features)<br>
File “/home/tfradai_gmail_com/anaconda3/envs/fast_cpu/lib/python3.7/site-packages/torch/nn/modules/module.py”, li<br>
ne 547, in <strong>call</strong><br>
result = self.forward(*input, **kwargs)<br>
File “/home/tfradai_gmail_com/anaconda3/envs/fast_cpu/lib/python3.7/site-packages/torchvision/models/densenet.py”<br>
, line 47, in forward<br>
if self.memory_efficient and any(prev_feature.requires_grad for prev_feature in prev_features):<br>
File “/home/tfradai_gmail_com/anaconda3/envs/fast_cpu/lib/python3.7/site-packages/torch/nn/modules/module.py”, li<br>
ne 591, in <strong>getattr</strong><br>
type(self).<strong>name</strong>, name))</p>
<p>no i sayall models(that i trained like resnet and se_resnet) except densenet</p>

mailcorahul: <p>You might be using an older version of torchvision models - ‘memory_efficient’ attribute is present only in densenet(reason why you were able to run resnets) and I guess this might be introduced in the newer versions of torchvision.</p>
<p>Do</p>
<pre><code class="lang-auto">pip install --upgrade torchvision
</code></pre>
<p>This should solve the issue. Also it would be better if you rename the title to something more specific to the problem <img src="https://discuss.pytorch.org/images/emoji/apple/slight_smile.png?v=9" title=":slight_smile:" class="emoji" alt=":slight_smile:"></p>

paulwababu: <p>pip install torchvision==0.2.0 --no-deps --no-cache-dir</p>
<p>You need torchvision 0.2.0</p>

Braun: <p>Hey, thanks for sharing this post did you get the answer because i am getting problems while solving<a href="https://www.upsers.page/" rel="noopener nofollow ugc">.</a></p>