我在运行大佬的程序中遇到的问题,特地记录在这。
AttributeError: 'Upsample' object has no attribute 'recompute_scale_factor'
在 models/yolo.py 中进行如下修改
def _forward_once(self, x, profile=False, visualize=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:
self._profile_one_layer(m, x, dt)
#this is where u have to update
if isinstance(m, nn.Upsample):
m.recompute_scale_factor = None
####
x = m(x) # run
y.append(x if m.i in self.save else None) # save output
# if visualize:
# feature_visualization(x, m.type, m.i, save_dir=visualize)
return x
File "D:\DJob\ML\yoloLite\utils\datasets.py", line 279, in init if 'youtube.com/' in url or 'youtu.be/' in url: # if source is YouTube video TypeError: argument of type 'int' is not iterable
注释“YouTube”那一部分。
n = len(sources)
self.imgs = [None] * n
self.sources = [clean_str(x) for x in sources] # clean source names for later
for i, s in enumerate(sources):
# Start the thread to read frames from the video stream
print(f'{i + 1}/{n}: {s}... ', end='')
url = eval(s) if s.isnumeric() else s
# if 'youtube.com/' in url or 'youtu.be/' in url: # if source is YouTube video
# check_requirements(('pafy', 'youtube_dl'))
# import pafy
# url = pafy.new(url).getbest(preftype="mp4").url
cap = cv2.VideoCapture(url)
assert cap.isOpened(), f'Failed to open {s}'
w = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH))
h = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))
self.fps = cap.get(cv2.CAP_PROP_FPS) % 100
_, self.imgs[i] = cap.read() # guarantee first frame
thread = Thread(target=self.update, args=([i, cap]), daemon=True)
print(f' success ({w}x{h} at {self.fps:.2f} FPS).')
thread.start()
print('') # newline