|
17 | 17 | import models
|
18 | 18 | from models.experimental import attempt_load
|
19 | 19 | from utils.activations import Hardswish, SiLU
|
20 |
| -from utils.general import colorstr, check_img_size, check_requirements, set_logging |
| 20 | +from utils.general import colorstr, check_img_size, check_requirements, file_size, set_logging |
21 | 21 | from utils.torch_utils import select_device
|
22 | 22 |
|
23 | 23 | if __name__ == '__main__':
|
|
60 | 60 | model.model[-1].export = not opt.grid # set Detect() layer grid export
|
61 | 61 | for _ in range(2):
|
62 | 62 | y = model(img) # dry runs
|
| 63 | + print(f"\n{colorstr('PyTorch:')} starting from {opt.weights} ({file_size(opt.weights):.1f} MB)") |
63 | 64 |
|
64 | 65 | # TorchScript export -----------------------------------------------------------------------------------------------
|
65 | 66 | prefix = colorstr('TorchScript:')
|
|
69 | 70 | ts = torch.jit.trace(model, img, strict=False)
|
70 | 71 | ts = optimize_for_mobile(ts) # https://pytorch.org/tutorials/recipes/script_optimized.html
|
71 | 72 | ts.save(f)
|
72 |
| - print(f'{prefix} export success, saved as {f}') |
| 73 | + print(f'{prefix} export success, saved as {f} ({file_size(f):.1f} MB)') |
73 | 74 | except Exception as e:
|
74 | 75 | print(f'{prefix} export failure: {e}')
|
75 | 76 |
|
|
103 | 104 | onnx.save(model_onnx, f)
|
104 | 105 | except Exception as e:
|
105 | 106 | print(f'{prefix} simplifier failure: {e}')
|
106 |
| - print(f'{prefix} export success, saved as {f}') |
| 107 | + print(f'{prefix} export success, saved as {f} ({file_size(f):.1f} MB)') |
107 | 108 | except Exception as e:
|
108 | 109 | print(f'{prefix} export failure: {e}')
|
109 | 110 |
|
|
117 | 118 | model = ct.convert(ts, inputs=[ct.ImageType(name='image', shape=img.shape, scale=1 / 255.0, bias=[0, 0, 0])])
|
118 | 119 | f = opt.weights.replace('.pt', '.mlmodel') # filename
|
119 | 120 | model.save(f)
|
120 |
| - print(f'{prefix} export success, saved as {f}') |
| 121 | + print(f'{prefix} export success, saved as {f} ({file_size(f):.1f} MB)') |
121 | 122 | except Exception as e:
|
122 | 123 | print(f'{prefix} export failure: {e}')
|
123 | 124 |
|
|
0 commit comments