|
@ -106,7 +106,7 @@ class Isc(NNOperator): |
|
|
img = img if self.skip_tfms else self.tfms(img) |
|
|
img = img if self.skip_tfms else self.tfms(img) |
|
|
img_list.append(img) |
|
|
img_list.append(img) |
|
|
inputs = torch.stack(img_list) |
|
|
inputs = torch.stack(img_list) |
|
|
inputs = inputs.to(self.device) |
|
|
|
|
|
|
|
|
inputs = inputs |
|
|
features = self.model(inputs) |
|
|
features = self.model(inputs) |
|
|
features = features.to('cpu') |
|
|
features = features.to('cpu') |
|
|
|
|
|
|
|
@ -138,7 +138,7 @@ class Isc(NNOperator): |
|
|
path = path + '.onnx' |
|
|
path = path + '.onnx' |
|
|
else: |
|
|
else: |
|
|
raise ValueError(f'Invalid format {format}.') |
|
|
raise ValueError(f'Invalid format {format}.') |
|
|
dummy_input = torch.rand(1, 3, 224, 224).to(self.device) |
|
|
|
|
|
|
|
|
dummy_input = torch.rand(1, 3, 224, 224) |
|
|
if format == 'pytorch': |
|
|
if format == 'pytorch': |
|
|
torch.save(self._model, path) |
|
|
torch.save(self._model, path) |
|
|
elif format == 'torchscript': |
|
|
elif format == 'torchscript': |
|
@ -153,7 +153,7 @@ class Isc(NNOperator): |
|
|
raise RuntimeError(f'Fail to save as torchscript: {e}.') |
|
|
raise RuntimeError(f'Fail to save as torchscript: {e}.') |
|
|
elif format == 'onnx': |
|
|
elif format == 'onnx': |
|
|
try: |
|
|
try: |
|
|
torch.onnx.export(self._model, |
|
|
|
|
|
|
|
|
torch.onnx.export(self._model.to('cpu'), |
|
|
dummy_input, |
|
|
dummy_input, |
|
|
path, |
|
|
path, |
|
|
input_names=['input_0'], |
|
|
input_names=['input_0'], |
|
|