How to run this github model

Arthur_Morgan: <p>I am learning pytorch… i have to implement this model from github…please someone guide me to implement it… it has different python functions… how to run this?</p>
<aside class="onebox allowlistedgeneric" data-onebox-src="https://github.com/VainF/DeepLabV3Plus-Pytorch">
  <header class="source">
      <img src="https://github.githubassets.com/favicons/favicon.svg" class="site-icon" width="32" height="32">

      <a href="https://github.com/VainF/DeepLabV3Plus-Pytorch" target="_blank" rel="noopener nofollow ugc">GitHub</a>
  </header>

  <article class="onebox-body">
    <div class="aspect-image" style="--aspect-ratio:690/345;"><img src="https://opengraph.githubassets.com/85cdd6a7b2b4a40445d4cb7b756ae5b11c9ccc8c7850a0a0c2f829dd0933a8ea/VainF/DeepLabV3Plus-Pytorch" class="thumbnail" width="690" height="345"></div>

<h3><a href="https://github.com/VainF/DeepLabV3Plus-Pytorch" target="_blank" rel="noopener nofollow ugc">GitHub - VainF/DeepLabV3Plus-Pytorch: Pretrained DeepLabv3 and DeepLabv3+ for...</a></h3>

  <p>Pretrained DeepLabv3 and DeepLabv3+ for Pascal VOC &amp; Cityscapes - GitHub - VainF/DeepLabV3Plus-Pytorch: Pretrained DeepLabv3 and DeepLabv3+ for Pascal VOC &amp; Cityscapes</p>


  </article>

  <div class="onebox-metadata">
    
    
  </div>

  <div style="clear: both"></div>
</aside>

<p>please…kindly help me…</p>

ptrblck: <p>Could you describe the issues you are facing or where exactly you are stuck?<br>
The repository seems to describe how to execute the model so are you stuck at executing any Python code? If so, I would recommend to take a look at a (free) beginner course to get familiar with Python a bit more.</p>

Arthur_Morgan: <p>thank you, i have done basic data science and ANN in tensorflow… this one is in pytorch…</p>
<p>what i did was that imported this repository into colab and then executed the commands as mentioned in the description but its now working.</p>
<p>The first command is</p>
<p>model = network.modeling.<strong>dict</strong>[deeplabv3_resnet50](num_classes=NUM_CLASSES, output_stride=OUTPUT_SRTIDE)</p>
<p>the error:<br>
NameError: name ‘network’ is not defined</p>
<p>but i have installed network using pip3.</p>
<p>I do not have deep knowledge in python… as you suggested i will go through python tutorials. but can you give a brief sketch of how to execute this?</p>

Arthur_Morgan: <p>I have understood how to predict single image, multiple images, run main.py ,VOC, cityscapes…</p>
<p>i have not understood how and where to run step 2,3</p>
<ol start="2">
<li>Load the pretrained model:</li>
</ol>
<p>model = network.modeling.<strong>dict</strong>[MODEL_NAME](num_classes=NUM_CLASSES, output_stride=OUTPUT_SRTIDE) model.load_state_dict( torch.load( PATH_TO_PTH )[‘model_state’] )</p>
<h3>
<a name="h-3-visualize-segmentation-outputs-1" class="anchor" href="#h-3-visualize-segmentation-outputs-1"></a>3. Visualize segmentation outputs:</h3>
<p>outputs = model(images) preds = outputs.max(1)[1].detach().cpu().numpy() colorized_preds = val_dst.decode_target(preds).astype(‘uint8’) # To RGB images, (N, H, W, 3), ranged 0~255, numpy array # Do whatever you like here with the colorized segmentation maps colorized_preds = Image.fromarray(colorized_preds[0]) # to PIL Image</p>

ptrblck: <p>The <code>network</code> namespace is defined in the repository directly <a href="https://github.com/VainF/DeepLabV3Plus-Pytorch/tree/master/network">here</a> so you might need to change the working directory in order to <code>import</code> it.</p>

Arthur_Morgan: <p>thank you,  i have run the following</p>
<p>–model = network.modeling.<strong>dict</strong>[‘deeplabv3_mobilenet’](num_classes=NUM_CLASSES, output_stride=OUTPUT_STRIDE)</p>
<p>it imported the corresponding pth file. Now in the next line of code, wehave to load it along with the model state.  i did the following.</p>
<p>–model_state=model.state_dict()</p>
<p>–checkpoint=torch.load(‘/root/.cache/torch/hub/checkpoints/mobilenet_v2-b0353104.pth’)</p>
<p>–model.load_state_dict(checkpoint[‘model_state’])<br>
for this line of code. I am getting the following error:<br>
----&gt; 3 model.load_state_dict(checkpoint[‘model_state’])<br>
KeyError: ‘model_state’</p>
<p>what to do now…</p>