Resources referenced in tutorial TorchVision Object Detection Finetuning Tutorial

username: JohnPolo
cooked: <p>I’m working with <a href="https://pytorch.org/tutorials/intermediate/torchvision_tutorial.html#defining-the-dataset" rel="noopener nofollow ugc">TorchVision Object Detection Finetuning Tutorial</a> in Google Colab and I’ve run into a few problems.</p>
<blockquote>
<p><a href="https://pytorch.org/tutorials/intermediate/torchvision_tutorial.html#putting-everything-together" rel="noopener nofollow ugc">## Putting everything together</a></p>
<p>In <code>references/detection/</code>, we have a number of helper functions to simplify training and evaluating detection models. Here, we will use <code>references/detection/engine.py</code>, <code>references/detection/utils.py</code> and <code>references/detection/transforms.py</code>. Just copy everything under <code>references/detection</code> to your folder and use them here.</p>
</blockquote>
<p>I don’t know what “/references/detection” refers to. I looked in the Resources section <a href="http://pytorch.org" rel="noopener nofollow ugc">pytorch.org</a> and nothing jumped out at me as the relevant section.</p>
<p>Missing the references section I think leads to this next problem:</p>
<pre><code class="lang-auto">import transforms as T

def get_transform(train):
    transforms = []
    transforms.append(T.ToTensor())
    if train:
        transforms.append(T.RandomHorizontalFlip(0.5))
    return T.Compose(transforms)
</code></pre>
<p>I get this error:</p>
<blockquote>
<hr>
<p>ModuleNotFoundError                       Traceback (most recent call last)</p>
<p> in ()<br>
----&gt; 1 import transforms as T<br>
2<br>
3 def get_transform(train):<br>
4     transforms = <span class="chcklst-box fa fa-square-o fa-fw"></span><br>
5     transforms.append(T.ToTensor())</p>
<p>ModuleNotFoundError: No module named ‘transforms’</p>
</blockquote>
<p>Another problem for me comes from this code:</p>
<pre><code class="lang-auto">data_loader = torch.utils.data.DataLoader(
 dataset, batch_size=2, shuffle=True, num_workers=4,
 collate_fn=utils.collate_fn)
</code></pre>
<p>I get an error message like the “utils” module cannot be found. I tried using the data loader before I realized that my data set still needed work. That’s potentially another question, but I think I am finally figuring out how to get my data to build the dataset. That’s still in the air, but getting close.</p>
<p>Another question has to do with:</p>
<pre><code class="lang-auto"># use our dataset and defined transformations
dataset = PennFudanDataset('PennFudanPed', get_transform(train=True))
dataset_test = PennFudanDataset('PennFudanPed', get_transform(train=False))
</code></pre>
<p>Where do the transformations come from? The code block for <code>torch.utils.data.Dataset</code><br>
only includes the line:<br>
<code>self.transforms = transforms</code></p>
<p>I looked <a href="https://pytorch.org/vision/stable/transforms.html" rel="noopener nofollow ugc">here</a> and couldn’t find anything that seems to create the “get_transform(train=True)” bit.</p>

username: KFrank
cooked: <p>Hi John!</p>
<aside class="quote no-group" data-username="JohnPolo" data-post="1" data-topic="123081" data-full="true">
<div class="title">
<div class="quote-controls"></div>
<img loading="lazy" alt="" width="24" height="24" src="https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/johnpolo/48/30779_2.png" class="avatar"> JohnPolo:</div>
<blockquote>
<p>I don’t know what “/references/detection” refers to.</p>
</blockquote>
</aside>
<p>I found it in pytorch’s github:  <a href="https://github.com/pytorch/vision/tree/master/references/detection" rel="noopener nofollow ugc">vision / references / detection</a>.  It contains,<br>
for example, <a href="https://github.com/pytorch/vision/blob/master/references/detection/engine.py" rel="noopener nofollow ugc">engine.py</a> and <a href="https://github.com/pytorch/vision/blob/master/references/detection/utils.py" rel="noopener nofollow ugc">utils.py</a>.</p>
<p>Best.</p>
<p>K. Frank</p>

username: JohnPolo
cooked: <p>Ah, yes, should have looked there to begin with. Thanks, K. Frank!</p>
<p>John</p>