if __name__ == '__main__': from f_pytorch.tools_model.model_look import f_look_tw ''' 模型测试 ''' cfg = CFG() cfg.NUMS_ANC = [3, 3, 3] cfg.NUM_CLASSES = 3 cfg.IMAGE_SIZE = (320, 320) cfg.STRIDES = [8, 16, 32, 64] cfg.MODE_TRAIN = 3 model = models.resnet18(pretrained=True) dims_out = (128, 256, 512) model = ModelOuts4Resnet(model, dims_out) # model = FcosNet_v1(model, cfg) # model = FcosNet_v2(model, cfg, o_ceng=4, num_conv=3) # model = FcosNet_v2(model, cfg, o_ceng=5, num_conv=3) model = FcosNet_v3(model, cfg, o_ceng=5, num_conv=3) model.train() # cfg.STRIDES = [8, 16, 32, 64, 128] # model = FcosNet(model, cfg, o_ceng=5) print(model(torch.rand(2, 3, 416, 416)).shape) # model.eval() f_look_tw(model, input=(1, 3, 320, 320), name='fcos') # from f_pytorch.tools_model.model_look import f_look_summary # f_look_summary(model)
with torch.no_grad(): # 这个没用 ids_batch, p_boxes_ltrb, p_keypoints, p_labels, p_scores = self.preder(outs, x) return ids_batch, p_boxes_ltrb, p_keypoints, p_labels, p_scores if __name__ == '__main__': model = darknet19(pretrained=True) model = ModelOuts4DarkNet19(model) # model = ModelOuts4DarkNet19(model) # model = models.resnet18(pretrained=True) # dims_out = (128, 256, 512) # model = ModelOuts4Resnet(model, dims_out) class CFG: pass cfg = CFG() cfg.NUM_CLASSES = 20 cfg.NUM_ANC = 5 net = Yolo_v2_Net(backbone=model, cfg=cfg) # x = torch.rand([5, 3, 416, 416]) # print(net(x).shape) from f_pytorch.tools_model.model_look import f_look_tw f_look_tw(net, input=(5, 3, 416, 416), name='Yolo_v2_Net')
outs, x) return ids_batch, p_boxes_ltrb, p_keypoints, p_labels, p_scores if __name__ == '__main__': class CFG: pass from f_pytorch.tools_model.f_layer_get import ModelOuts4Resnet from f_pytorch.tools_model.model_look import f_look_tw cfg = CFG() cfg.NUMS_ANC = [3, 3, 3] cfg.NUM_CLASSES = 3 cfg.IMAGE_SIZE = (416, 416) cfg.ANCS_SCALE = [[0.06, 0.06], [0.122, 0.098], [0.18, 0.19], [0.382, 0.251], [0.262, 0.378], [0.408, 0.529], [0.621, 0.415], [0.622, 0.704], [0.85, 0.61]] cfg.FEATURE_MAP_STEPS = [8, 16, 32, 64, 128] cfg.NUM_KEYPOINTS = 5 model = models.resnet18(pretrained=True) dims_out = (128, 256, 512) model = ModelOuts4Resnet(model, dims_out) model = Retina_Net2(model, cfg) f_look_tw(model, input=(1, 3, 416, 416), name='Retina_Net') # f_look_summary(model, input=(3, 416, 416)) # model(torch.randn((2, 3, 416, 416)))
[0.07, 0.078], [0.106, 0.052], [0.054, 0.158], [0.084, 0.114], [0.146, 0.092], [0.078, 0.21], [0.118, 0.154], [0.15, 0.204], [0.106, 0.294], [0.242, 0.13], [0.212, 0.234], [0.162, 0.382], [0.422, 0.198], [0.298, 0.288], [0.23, 0.412], [0.47, 0.31], [0.34, 0.444], [0.274, 0.62187], [0.792, 0.268], [0.57806, 0.42], [0.432, 0.6], [0.843, 0.49], [0.64, 0.732], [0.942, 0.662], ] # net = SSD_Net(backbone=model, num_classes=cfg.NUM_CLASSES, cfg=cfg) model = SSD(backbone=model, cfg=cfg, device=torch.device('cpu')) from f_pytorch.tools_model.model_look import f_look_tw f_look_tw(model, input=(1, 3, 300, 300), name='SSD_Net')
# 可以不要返回值 self.preder(outs, x, *args) return else: ids_batch, p_boxes_ltrb, p_keypoints, p_labels, p_scores = self.preder(outs, x, *args) return ids_batch, p_boxes_ltrb, p_keypoints, p_labels, p_scores # if torch.jit.is_scripting(): # 这里是生产环境部署 if __name__ == '__main__': from torchvision import models from f_pytorch.tools_model.model_look import f_look_tw # model = models.mobilenet_v2(pretrained=True) # model = ModelOuts4Mobilenet_v2(model) # dims_out = [256, 512, 1024] class cfg: pass cfg.NUM_CLASSES = 3 model = models.resnet18(pretrained=True) model = ModelOut4Resnet18(model) model = CenterNet(backbone=model, cfg=cfg, ) model.eval() # 输出是 tuple 要报错但可以生成 f_look_tw(model, input=(1, 3, 512, 512), name='CenterNet')
if targets is None: raise ValueError("In training mode, targets should be passed") loss_total, log_dict = self.losser(outs, targets, x) '''------验证loss 待扩展------''' return loss_total, log_dict else: with torch.no_grad(): # 这个没用 ids_batch, p_boxes_ltrb, p_keypoints, p_labels, p_scores = self.preder( outs, x) return ids_batch, p_boxes_ltrb, p_keypoints, p_labels, p_scores if __name__ == '__main__': from torchvision import models from f_pytorch.tools_model.f_layer_get import ModelOut4Resnet18 model = models.resnet18(pretrained=True) model = ModelOut4Resnet18(model) class CFG: pass cfg = CFG() cfg.NUM_CLASSES = 3 net = YOLOv1_Net(backbone=model, cfg=cfg) from f_pytorch.tools_model.model_look import f_look_tw f_look_tw(net, input=(5, 3, 416, 416), name='YOLOv1_Net')