ultralytics / yolov5

YOLOv5 🚀 in PyTorch > ONNX > CoreML > TFLite
https://docs.ultralytics.com
GNU Affero General Public License v3.0
50.84k stars 16.37k forks source link

ambiguity of the from index "f" #371

Closed ping28198 closed 4 years ago

ping28198 commented 4 years ago

Exist ambiguity of the from index "f" in function "parse_model" and member function "forward_once" of class "Model"

def parse_model(md, ch): # model_dict, input_channels(3) print('\n%3s%18s%3s%10s %-40s%-30s' % ('', 'from', 'n', 'params', 'module', 'arguments')) anchors, nc, gd, gw = md['anchors'], md['nc'], md['depth_multiple'], md['width_multiple'] na = (len(anchors[0]) // 2) # number of anchors no = na (nc + 5) # number of outputs = anchors (classes + 5) layers, save, c2 = [], [], ch[-1] # layers, savelist, ch out for i, (f, n, m, args) in enumerate(md['backbone'] + md['head']): # from, number, module, args m = eval(m) if isinstance(m, str) else m # eval strings for j, a in enumerate(args): try: args[j] = eval(a) if isinstance(a, str) else a # eval strings except: pass n = max(round(n * gd), 1) if n > 1 else n # depth gain if m in [nn.Conv2d, Conv, Bottleneck, SPP, DWConv, MixConv2d, Focus, CrossConv, BottleneckCSP, C3]: c1, c2 = ch[f], args[0]

def forward_once(self, x, profile=False):

y, dt = [], [] # outputs for m in self.model: if m.f != -1: # if not from previous layer x = y[m.f] if isinstance(m.f, int) else [x if j == -1 else y[j] for j in m.f] # from earlier layers if profile: try: import thop o = thop.profile(m, inputs=(x,), verbose=False)[0] / 1E9 2 # FLOPS except: o = 0 t = torch_utils.timesynchronized() for in range(10): _ = m(x) dt.append((torch_utils.time_synchronized() - t) 100) print('%10.1f%10.0f%10.1fms %-40s' % (o, m.np, dt[-1], m.type)) x = m(x) # run y.append(x if m.i in self.save else None) # save output

In the function "parse model" , the "f" include the original input, yes the raw image which has channel numble 3. However, In the member function "forward_once", the "f" do not include the original input. I am confused by this.

Environment

If applicable, add screenshots to help explain your problem.

github-actions[bot] commented 4 years ago

Hello @ping28198, thank you for your interest in our work! Please visit our Custom Training Tutorial to get started, and see our Jupyter Notebook Open In Colab, Docker Image, and Google Cloud Quickstart Guide for example environments.

If this is a bug report, please provide screenshots and minimum viable code to reproduce your issue, otherwise we can not help you.

If this is a custom model or data training question, please note that Ultralytics does not provide free personal support. As a leader in vision ML and AI, we do offer professional consulting, from simple expert advice up to delivery of fully customized, end-to-end production solutions for our clients, such as:

For more information please visit https://www.ultralytics.com.

glenn-jocher commented 4 years ago

@ping28198 I don't understand the question. If you are proposing improvements please show your proposed code or submit a PR please. Thank you.

github-actions[bot] commented 4 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.