'NoneType' object has no attribute

username: KanZa
cooked: <p>When I implement the following code:<br>
</p><aside class="onebox githubblob">
  <header class="source">
      <a href="https://github.com/leaderj1001/Billion-scale-semi-supervised-learning/blob/master/make_sample_data.py" target="_blank" rel="nofollow noopener">github.com</a>
  </header>
  <article class="onebox-body">
    <h4><a href="https://github.com/leaderj1001/Billion-scale-semi-supervised-learning/blob/master/make_sample_data.py" target="_blank" rel="nofollow noopener">leaderj1001/Billion-scale-semi-supervised-learning/blob/master/make_sample_data.py</a></h4>
<pre><code class="lang-py">import torch
import torch.nn.functional as F
import cv2
import numpy as np
import os
import glob
import argparse
import json
import random
import codecs

from model import resnet50

use_cuda = torch.cuda.is_available()
device = torch.device('cuda' if use_cuda else 'cpu')


def get_args():
    parser = argparse.ArgumentParser("parameters")

</code></pre>

  This file has been truncated. <a href="https://github.com/leaderj1001/Billion-scale-semi-supervised-learning/blob/master/make_sample_data.py" target="_blank" rel="nofollow noopener">show original</a>

  </article>
  <div class="onebox-metadata">
    
    
  </div>
  <div style="clear: both"></div>
</aside>

<p>It gives me the following error<br>
File “make_sample_data.py”, line 149, in <br>
main(args)<br>
File “make_sample_data.py”, line 132, in main<br>
if args.load_pretrained:<br>
AttributeError: ‘NoneType’ object has no attribute ‘load_pretrained’</p>

username: ptrblck
cooked: <p>Could you check, which attributes <code>args</code> contains?<br>
I just tried to <code>argparse</code> code and it’s working correctly and returns <code>True</code> as the default for <code>args.load_pretrained</code>.</p>

username: KanZa
cooked: <p>I am sorry, I am not getting. it is still showing same error.</p>

username: ptrblck
cooked: <p>Add a print statement after <a href="https://github.com/leaderj1001/Billion-scale-semi-supervised-learning/blob/f3f2dc77dc58ec02dd5108a61dff3496b03ae0e8/make_sample_data.py#L147">line 147</a> as <code>print(args)</code> and check, if <code>args.load_pretrained</code> is defined and if so which value it’s using.</p>

username: KanZa
cooked: <p>it is not printing anything and showing same error<br>
Traceback (most recent call last):<br>
File “make_sample_data.py”, line 150, in <br>
main(args)<br>
File “make_sample_data.py”, line 131, in main<br>
if args.load_pretrained:<br>
AttributeError: ‘NoneType’ object has no attribute ‘load_pretrained’</p>

username: ptrblck
cooked: <p>In that case the <code>get_args</code> method returns <code>None</code> and I don’t know why this would be the case.<br>
Are you running your script in a Jupyter notebook? If so, could you use a terminal and rerun the script?</p>

username: KanZa
cooked: <p>No, I am not running on Jupyter, I am running on Visual studio and I also run on terminal. It is still giving same error.</p>

username: ptrblck
cooked: <p>Sorry, in that case I don’t know what might be causing this issue, as this code snippet successfully returns the default arguments:</p>
<pre><code class="lang-python">def get_args():
    parser = argparse.ArgumentParser("parameters")

    parser.add_argument('--p', type=int, default=10, help='P being a parameter accounting for the fact that we expect only a few number of relevant classes to occur in each image. (default: 10)')
    parser.add_argument('--k', type=int, default=1000, help=', there is an important trade-off on K that strongly depends on the ratio K/M. (default: 1000)')
    parser.add_argument('--batch-size', type=int, default=100, help='batch size, (default: 100)')
    parser.add_argument('--input-size', type=tuple, default=(32, 32), help='input data size, (default: (32, 32))')
    parser.add_argument('--load-pretrained', type=bool, default=True)

    args = parser.parse_args()

    return args

args = get_args()
print(args)
&gt; Namespace(batch_size=100, input_size=(32, 32), k=1000, load_pretrained=True, p=10)
print(args.load_pretrained)
&gt; True
</code></pre>
<p>It seems that your current environment isn’t able to parse the arguments and based on this I would recommend to post the issue (without the PyTorch code) on e.g. StackOverflow.</p>