Undergraduate engineering students cv code change
I originally did 7, but the 7 error has not been resolved, so I will try 5
1. The first error is reported first
TypeError: __init__() missing 1 required positional argument: 'c2'
Solution: in yolo.py
if m in {
Conv, GhostConv, Bottleneck, GhostBottleneck, SPP, SPPF, DWConv, MixConv2d, Focus, CrossConv,
BottleneckCSP, C3, C3TR, C3SPP, C3Ghost, nn.ConvTranspose2d, DWConvTranspose2d, C3x, C3STR}:
# add a C3STR at the end of the sentence(aran)
c1, c2 = ch[f], args[0]
if c2 != no: # if not output
c2 = make_divisible(c2 * gw, 8) # change 8 to 9
args = [c1, c2, *args[1:]]
if m in {BottleneckCSP, C3, C3TR, C3Ghost, C3x, C3STR}:# add a C3STR at the end of the sentence(aran)
args.insert(2, n) # number of repeats
2、
File "/root/yolov5_master/models/common.py", line 1315, in __init__
super().__init__(c1, c2, c2, n, shortcut, g, e)
TypeError: __init__() takes from 3 to 7 positional arguments but 8 were given
Solution: delete a c2 in common
class C3STR(C3):
# C3 module with SwinTransformerBlock()
def __init__(self, c1, c2, n=1, shortcut=True, g=1, e=0.5):
super().__init__(c1, c2, n, shortcut, g, e) # a c2 was deleted by aran
c_ = int(c2 * e)
num_heads = c_ // 32
self.m = SwinTransformerBlock(c_, c_, num_heads, n)
3、
NameError: name 'window_partition' is not defined
Solution: You should add window_partition and window_reverse to common, and the specific location is to add it in front of the common code in Mango
def window_partition(x, window_size):
B, H, W, C = x.shape
x = x.view(B, H // window_size, window_size, W // window_size, window_size, C)
windows = x.permute(0, 1, 3, 2, 4, 5).contiguous().view(-1, window_size, window_size, C)
return windows
def window_reverse(windows, window_size, H, W):
B = int(windows.shape[0] / (H * W / window_size / window_size))
x = windows.view(B, H // window_size, W // window_size, window_size, window_size, -1)
x = x.permute(0, 1, 3, 2, 4, 5).contiguous().view(B, H, W, -1)
return x
4、
NameError: name 'F' is not defined
Solution: in common
import torch.nn.functional as F