diff options
author | Jordan Gong <jordan.gong@protonmail.com> | 2021-01-12 20:39:50 +0800 |
---|---|---|
committer | Jordan Gong <jordan.gong@protonmail.com> | 2021-01-12 20:39:50 +0800 |
commit | cad72ca5f1f3f7fc37ce3429af0bf255fed453fb (patch) | |
tree | 9a5b6e42d822779f4a628a39f7744290758849d1 /models/model.py | |
parent | 2fa77264fb5002683da902577acea6451e4c2942 (diff) | |
parent | 37e307b960d565e7a58dfd22d0506c0f6f4fd122 (diff) |
Merge branch 'python3.8' into python3.7
Diffstat (limited to 'models/model.py')
-rw-r--r-- | models/model.py | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/models/model.py b/models/model.py index af37bb2..b7bde9e 100644 --- a/models/model.py +++ b/models/model.py @@ -112,11 +112,11 @@ class Model: optim_hp = self.hp.get('optimizer', {}) sched_hp = self.hp.get('scheduler', {}) self.rgb_pn = RGBPartNet(self.train_size, self.in_channels, **model_hp) + # Try to accelerate computation using CUDA or others + self.rgb_pn = self._accelerate(self.rgb_pn) self.optimizer = optim.Adam(self.rgb_pn.parameters(), **optim_hp) self.scheduler = optim.lr_scheduler.StepLR(self.optimizer, **sched_hp) self.writer = SummaryWriter(self._log_name) - # Try to accelerate computation using CUDA or others - self._accelerate() self.rgb_pn.train() # Init weights at first iter @@ -173,11 +173,12 @@ class Model: self.writer.close() break - def _accelerate(self): + def _accelerate(self, model: nn.Module) -> nn.Module: if not self.disable_acc: if torch.cuda.device_count() > 1: - self.rgb_pn = nn.DataParallel(self.rgb_pn) - self.rgb_pn = self.rgb_pn.to(self.device) + model = nn.DataParallel(model) + model = model.to(self.device) + return model def predict_all( self, @@ -201,7 +202,7 @@ class Model: model_hp = self.hp.get('model', {}) self.rgb_pn = RGBPartNet(ae_in_channels=self.in_channels, **model_hp) # Try to accelerate computation using CUDA or others - self._accelerate() + self.rgb_pn = self._accelerate(self.rgb_pn) self.rgb_pn.eval() gallery_samples, probe_samples = [], {} |