第二次分析(第一次的代码以找回,在下面一节)
在yolo.py里面加入如下代码并运行,注意在前面用sys.path.appen()加入utils和models文件夹的路径。
if __name__ == '__main__':
cfg = 'yolov5s.yaml'
ch = 3
import yaml
with open(cfg, encoding='ascii', errors='ignore') as f:
cfg = yaml.safe_load(f) #
model,save = parse_model(cfg,[ch])
y = []
x = torch.rand(4,3,640,640)
for m in model:
print(f'layer name:{
m.type}, from :{
m.f} index: {
m.i}')
if m.f != -1 :
x = y[m.f] if isinstance(m.f, int) else [x if j == -1 else y[j] for j in m.f]
if isinstance(x,torch.Tensor):
print(f'shape of input: {
x.shape }')