Beispiel #1
0
 def complexity(cx, w_in, w_se):
     h, w = cx["h"], cx["w"]
     cx["h"], cx["w"] = 1, 1
     cx = nu.complexity_conv2d(cx, w_in, w_se, 1, 1, 0, bias=True)
     cx = nu.complexity_conv2d(cx, w_se, w_in, 1, 1, 0, bias=True)
     cx["h"], cx["w"] = h, w
     return cx
Beispiel #2
0
 def complexity(cx, w_in, w_out, stride, w_b=None, num_gs=1):
     err_str = "Basic transform does not support w_b and num_gs options"
     assert w_b is None and num_gs == 1, err_str
     cx = nu.complexity_conv2d(cx, w_in, w_out, 3, stride, 1)
     cx = nu.complexity_batchnorm2d(cx, w_out)
     cx = nu.complexity_conv2d(cx, w_out, w_out, 3, 1, 1)
     cx = nu.complexity_batchnorm2d(cx, w_out)
     return cx
Beispiel #3
0
 def complexity(cx, w_in, w_out, stride, bm=None, gw=None, se_r=None):
     err_str = "Vanilla block does not support bm, gw, and se_r options"
     assert bm is None and gw is None and se_r is None, err_str
     cx = nu.complexity_conv2d(cx, w_in, w_out, 3, stride, 1)
     cx = nu.complexity_batchnorm2d(cx, w_out)
     cx = nu.complexity_conv2d(cx, w_out, w_out, 3, 1, 1)
     cx = nu.complexity_batchnorm2d(cx, w_out)
     return cx
Beispiel #4
0
 def complexity(cx, w_in, w_out, stride, w_b, num_gs):
     (s1, s3) = (stride, 1) if cfg.RESNET.STRIDE_1X1 else (1, stride)
     cx = nu.complexity_conv2d(cx, w_in, w_b, 1, s1, 0)
     cx = nu.complexity_batchnorm2d(cx, w_b)
     cx = nu.complexity_conv2d(cx, w_b, w_b, 3, s3, 1, num_gs)
     cx = nu.complexity_batchnorm2d(cx, w_b)
     cx = nu.complexity_conv2d(cx, w_b, w_out, 1, 1, 0)
     cx = nu.complexity_batchnorm2d(cx, w_out)
     return cx
Beispiel #5
0
 def complexity(cx, w_in, exp_r, kernel, stride, se_r, w_out):
     w_exp = int(w_in * exp_r)
     if w_exp != w_in:
         cx = nu.complexity_conv2d(cx, w_in, w_exp, 1, 1, 0)
         cx = nu.complexity_batchnorm2d(cx, w_exp)
     padding = (kernel - 1) // 2
     cx = nu.complexity_conv2d(cx, w_exp, w_exp, kernel, stride, padding,
                               w_exp)
     cx = nu.complexity_batchnorm2d(cx, w_exp)
     cx = SE.complexity(cx, w_exp, int(w_in * se_r))
     cx = nu.complexity_conv2d(cx, w_exp, w_out, 1, 1, 0)
     cx = nu.complexity_batchnorm2d(cx, w_out)
     return cx
Beispiel #6
0
 def complexity(cx, w_in, w_out, stride, bm, gw, se_r):
     w_b = int(round(w_out * bm))
     g = w_b // gw
     cx = nu.complexity_conv2d(cx, w_in, w_b, 1, 1, 0)
     cx = nu.complexity_batchnorm2d(cx, w_b)
     cx = nu.complexity_conv2d(cx, w_b, w_b, 3, stride, 1, g)
     cx = nu.complexity_batchnorm2d(cx, w_b)
     if se_r:
         w_se = int(round(w_in * se_r))
         cx = SE.complexity(cx, w_b, w_se)
     cx = nu.complexity_conv2d(cx, w_b, w_out, 1, 1, 0)
     cx = nu.complexity_batchnorm2d(cx, w_out)
     return cx
Beispiel #7
0
 def complexity(cx, w_in, w_out, stride, trans_fun, w_b, num_gs):
     proj_block = (w_in != w_out) or (stride != 1)
     if proj_block:
         h, w = cx["h"], cx["w"]
         cx = nu.complexity_conv2d(cx, w_in, w_out, 1, stride, 0)
         cx = nu.complexity_batchnorm2d(cx, w_out)
         cx["h"], cx["w"] = h, w  # parallel branch
     cx = trans_fun.complexity(cx, w_in, w_out, stride, w_b, num_gs)
     return cx
Beispiel #8
0
 def complexity(cx, w_in, w_out, stride, bm=1.0, gw=1, se_r=None):
     proj_block = (w_in != w_out) or (stride != 1)
     if proj_block:
         h, w = cx["h"], cx["w"]
         cx = nu.complexity_conv2d(cx, w_in, w_out, 1, stride, 0)
         cx = nu.complexity_batchnorm2d(cx, w_out)
         cx["h"], cx["w"] = h, w  # parallel branch
     cx = BottleneckTransform.complexity(cx, w_in, w_out, stride, bm, gw,
                                         se_r)
     return cx
Beispiel #9
0
 def complexity(cx, w_in, w_out, stride, bm=None, gw=None, se_r=None):
     err_str = "Basic transform does not support bm, gw, and se_r options"
     assert bm is None and gw is None and se_r is None, err_str
     proj_block = (w_in != w_out) or (stride != 1)
     if proj_block:
         h, w = cx["h"], cx["w"]
         cx = nu.complexity_conv2d(cx, w_in, w_out, 1, stride, 0)
         cx = nu.complexity_batchnorm2d(cx, w_out)
         cx["h"], cx["w"] = h, w  # parallel branch
     cx = BasicTransform.complexity(cx, w_in, w_out, stride)
     return cx
Beispiel #10
0
 def complexity(cx, w_in, nc):
     cx["h"], cx["w"] = 1, 1
     cx = nu.complexity_conv2d(cx, w_in, nc, 1, 1, 0, bias=True)
     return cx
Beispiel #11
0
 def complexity(cx, w_in, w_out):
     cx = nu.complexity_conv2d(cx, w_in, w_out, 7, 2, 3)
     cx = nu.complexity_batchnorm2d(cx, w_out)
     cx = nu.complexity_maxpool2d(cx, 3, 2, 1)
     return cx
Beispiel #12
0
 def complexity(cx, w_in, w_out):
     cx = nu.complexity_conv2d(cx, w_in, w_out, 3, 1, 1)
     cx = nu.complexity_batchnorm2d(cx, w_out)
     return cx
Beispiel #13
0
 def complexity(cx, w_in, w_out, nc):
     cx = nu.complexity_conv2d(cx, w_in, w_out, 1, 1, 0)
     cx = nu.complexity_batchnorm2d(cx, w_out)
     cx["h"], cx["w"] = 1, 1
     cx = nu.complexity_conv2d(cx, w_out, nc, 1, 1, 0, bias=True)
     return cx