Closed jaskiratsingh2000 closed 3 years ago
@glenn-jocher Your response and a bit of help would really be appreciable. Can you please let me know?
@jaskiratsingh2000 I already answered this question previously in https://github.com/ultralytics/yolov5/issues/2898#issuecomment-827129027
@glenn-jocher Things were not clear for me. when I run the following command here https://colab.research.google.com/drive/1PRjPmQ8Nk7oM0KUcGfMBLVWSyNQ29lih?usp=sharing
You mentioned running this following command with profiling made to true:
img = torch.rand(8 if torch.cuda.is_available() else 1, 3, 320, 320).to(device)
y = model(img, profile=True)
but I am getting this error:
NameError Traceback (most recent call last)
<ipython-input-4-f21874f58c27> in <module>()
----> 1 img = torch.rand(8 if torch.cuda.is_available() else 1, 3, 320, 320).to(device)
2 y = model(img, profile=True)
NameError: name 'device' is not defined
If I change the "device" to 'cuda' I still get lots of runtime errors. Can you please check and let me know exactly here? @glenn-jocher
@glenn-jocher I tried creating the device by following the command:
device = torch.device("cuda:0")
and then creating the model:
model = torch.hub.load('ultralytics/yolov5', 'yolov5s', force_reload=True)
then on running the profiling commands I get the following out put and runtime errors.
time (ms) GFLOPS params module
3.71 1.44 3520 models.common.Focus
2.87 1.90 18560 models.common.Conv
7.84 1.93 18816 models.common.C3
1.71 1.89 73984 models.common.Conv
6.98 4.02 156928 models.common.C3
1.42 1.89 295424 models.common.Conv
4.65 4.00 625152 models.common.C3
1.54 1.89 1180672 models.common.Conv
2.15 1.05 656896 models.common.SPP
2.54 1.89 1182720 models.common.C3
0.29 0.21 131584 models.common.Conv
0.10 0.00 0 torch.nn.modules.upsampling.Upsample
0.29 0.00 0 models.common.Concat
2.33 2.32 361984 models.common.C3
0.29 0.21 33024 models.common.Conv
0.15 0.00 0 torch.nn.modules.upsampling.Upsample
0.25 0.00 0 models.common.Concat
3.15 2.33 90880 models.common.C3
0.73 0.95 147712 models.common.Conv
0.16 0.00 0 models.common.Concat
2.05 1.90 296448 models.common.C3
0.92 0.94 590336 models.common.Conv
0.07 0.00 0 models.common.Concat
2.30 1.89 1182720 models.common.C3
---------------------------------------------------------------------------
RuntimeError Traceback (most recent call last)
<ipython-input-7-f21874f58c27> in <module>()
1 img = torch.rand(8 if torch.cuda.is_available() else 1, 3, 320, 320).to(device)
----> 2 y = model(img, profile=True)
10 frames
/usr/local/lib/python3.7/dist-packages/torch/nn/modules/module.py in _call_impl(self, *input, **kwargs)
887 result = self._slow_forward(*input, **kwargs)
888 else:
--> 889 result = self.forward(*input, **kwargs)
890 for hook in itertools.chain(
891 _global_forward_hooks.values(),
/usr/local/lib/python3.7/dist-packages/torch/autograd/grad_mode.py in decorate_context(*args, **kwargs)
25 def decorate_context(*args, **kwargs):
26 with self.__class__():
---> 27 return func(*args, **kwargs)
28 return cast(F, decorate_context)
29
/root/.cache/torch/hub/ultralytics_yolov5_master/models/common.py in forward(self, imgs, size, augment, profile)
253 if isinstance(imgs, torch.Tensor): # torch
254 with amp.autocast(enabled=p.device.type != 'cpu'):
--> 255 return self.model(imgs.to(p.device).type_as(p), augment, profile) # inference
256
257 # Pre-process
/usr/local/lib/python3.7/dist-packages/torch/nn/modules/module.py in _call_impl(self, *input, **kwargs)
887 result = self._slow_forward(*input, **kwargs)
888 else:
--> 889 result = self.forward(*input, **kwargs)
890 for hook in itertools.chain(
891 _global_forward_hooks.values(),
/root/.cache/torch/hub/ultralytics_yolov5_master/models/yolo.py in forward(self, x, augment, profile)
122 return torch.cat(y, 1), None # augmented inference, train
123 else:
--> 124 return self.forward_once(x, profile) # single-scale inference, train
125
126 def forward_once(self, x, profile=False):
/root/.cache/torch/hub/ultralytics_yolov5_master/models/yolo.py in forward_once(self, x, profile)
134 t = time_synchronized()
135 for _ in range(10):
--> 136 _ = m(x)
137 dt.append((time_synchronized() - t) * 100)
138 if m == self.model[0]:
/usr/local/lib/python3.7/dist-packages/torch/nn/modules/module.py in _call_impl(self, *input, **kwargs)
887 result = self._slow_forward(*input, **kwargs)
888 else:
--> 889 result = self.forward(*input, **kwargs)
890 for hook in itertools.chain(
891 _global_forward_hooks.values(),
/root/.cache/torch/hub/ultralytics_yolov5_master/models/yolo.py in forward(self, x)
44 self.training |= self.export
45 for i in range(self.nl):
---> 46 x[i] = self.m[i](x[i]) # conv
47 bs, _, ny, nx = x[i].shape # x(bs,255,20,20) to x(bs,3,20,20,85)
48 x[i] = x[i].view(bs, self.na, self.no, ny, nx).permute(0, 1, 3, 4, 2).contiguous()
/usr/local/lib/python3.7/dist-packages/torch/nn/modules/module.py in _call_impl(self, *input, **kwargs)
887 result = self._slow_forward(*input, **kwargs)
888 else:
--> 889 result = self.forward(*input, **kwargs)
890 for hook in itertools.chain(
891 _global_forward_hooks.values(),
/usr/local/lib/python3.7/dist-packages/torch/nn/modules/conv.py in forward(self, input)
397
398 def forward(self, input: Tensor) -> Tensor:
--> 399 return self._conv_forward(input, self.weight, self.bias)
400
401 class Conv3d(_ConvNd):
/usr/local/lib/python3.7/dist-packages/torch/nn/modules/conv.py in _conv_forward(self, input, weight, bias)
394 _pair(0), self.dilation, self.groups)
395 return F.conv2d(input, weight, bias, self.stride,
--> 396 self.padding, self.dilation, self.groups)
397
398 def forward(self, input: Tensor) -> Tensor:
RuntimeError: Expected 4-dimensional input for 4-dimensional weight [255, 128, 1, 1], but got 5-dimensional input of size [8, 3, 40, 40, 85] instead
Hey, @glenn-jocher Did you get a chance to check on the above? I am still not able to produce the output you mentioned. Please help me out in knowing about this. It would be highly appreciative of your response and help. Thanks
@jaskiratsingh2000 my previous response answers your question: https://github.com/ultralytics/yolov5/issues/2898#issuecomment-827129027
@glenn-jocher It does answer my question but things are not clear to me exactly what I have to do. What you mentioned in this comment I ran the model that way but I am getting the error as stated above that's why I am pinging you that I am stuck here please help me with that if possible. I would really be grateful to you.
@glenn-jocher you told me to run directly this and when I run that I get the above runtime error.
img = torch.rand(8 if torch.cuda.is_available() else 1, 3, 320, 320).to(device)
y = model(img, profile=True)
If you follow https://github.com/ultralytics/yolov5/issues/2898#issuecomment-827129027 and you are seeing errors then either you have modified your code, your code is out of date, or you have environment problems. See below.
👋 Hello, thank you for your interest in our work! This issue seems to lack the minimum requirements for a proper response, or is insufficiently detailed for us to help you. Please note that most technical problems are due to:
git clone
version of this repo we can not debug it. Before going further run this code and verify your issue persists:
$ git clone https://github.com/ultralytics/yolov5 yolov5_new # clone latest
$ cd yolov5_new
$ python detect.py # verify detection
- **Your custom data.** If your issue is not reproducible in one of our 3 common datasets ([COCO](https://github.com/ultralytics/yolov5/blob/master/data/coco.yaml), [COCO128](https://github.com/ultralytics/yolov5/blob/master/data/coco128.yaml), or [VOC](https://github.com/ultralytics/yolov5/blob/master/data/voc.yaml)) we can not debug it. Visit our [Custom Training Tutorial](https://docs.ultralytics.com/yolov5/tutorials/train_custom_data) for guidelines on training your custom data. Examine `train_batch0.jpg` and `test_batch0.jpg` for a sanity check of your labels and images.
- **Your environment.** If your issue is not reproducible in one of the verified environments below we can not debug it. If you are running YOLOv5 locally, verify your environment meets all of the [requirements.txt](https://github.com/ultralytics/yolov5/blob/master/requirements.txt) dependencies specified below. If in doubt, download Python 3.8.0 from https://www.python.org/, create a new [venv](https://packaging.python.org/guides/installing-using-pip-and-virtual-environments/), and install requirements.
If none of these apply to you, we suggest you close this issue and raise a new one using the 🐛 **Bug Report template**, providing screenshots and a [minimum reproducible example](https://docs.ultralytics.com/help/minimum_reproducible_example/) of your issue. Thank you!
## Requirements
Python 3.8 or later with all [requirements.txt](https://github.com/ultralytics/yolov5/blob/master/requirements.txt) dependencies installed, including `torch>=1.7`. To install run:
```bash
$ pip install -r requirements.txt
YOLOv5 may be run in any of the following up-to-date verified environments (with all dependencies including CUDA/CUDNN, Python and PyTorch preinstalled):
If this badge is green, all YOLOv5 GitHub Actions Continuous Integration (CI) tests are passing. These tests evaluate proper operation of basic YOLOv5 functionality, including training (train.py), testing (test.py), inference (detect.py) and export (export.py) on MacOS, Windows, and Ubuntu.
I am not sure if you are able to get me. I ran the steps you mentioned got an error then raised above. I am just asking about the way you produce it. What all things and commands you ran
@jaskiratsingh2000 The variable 'device' is already listed in the main function on yolo.py
.
See line 262, so you don't need to write another like you doing in the https://github.com/ultralytics/yolov5/issues/2951#issuecomment-828199379. You just uncomment in line 269-270. And this line https://github.com/ultralytics/yolov5/blob/184991672636838453e796f72268833dff788d07/models/yolo.py#L41
Then you just run !python yolo.py
in your colab.
❔Question
Getting error while producing latency through yolo.py
Additional context
I want to view the latency output as discussed in issue #2898 but I feel like this is an issue that should go independently. I want to produce this output:
I was able to produce the parameter output by running the following commands
@glenn-jocher mentioned that I can get the output of the latency of layer by layer which is the following
by running the model here https://github.com/ultralytics/yolov5/issues/2898#issuecomment-827129027 whereas, I am unable to do that because as I run this command to produce the above out I get the error.
command run:
Error got: