| 4 | from .networks import get_grid |
| 5 | |
| 6 | class BaseModel(torch.nn.Module): |
| 7 | def name(self): |
| 8 | return 'BaseModel' |
| 9 | |
| 10 | def initialize(self, opt): |
| 11 | self.opt = opt |
| 12 | self.gpu_ids = opt.gpu_ids |
| 13 | self.isTrain = opt.isTrain |
| 14 | self.Tensor = torch.cuda.FloatTensor if self.gpu_ids else torch.Tensor |
| 15 | self.save_dir = os.path.join(opt.checkpoints_dir, opt.name) |
| 16 | |
| 17 | def set_input(self, input): |
| 18 | self.input = input |
| 19 | |
| 20 | def forward(self): |
| 21 | pass |
| 22 | |
| 23 | # used in test time, no backprop |
| 24 | def test(self): |
| 25 | pass |
| 26 | |
| 27 | def get_image_paths(self): |
| 28 | pass |
| 29 | |
| 30 | def optimize_parameters(self): |
| 31 | pass |
| 32 | |
| 33 | def get_current_visuals(self): |
| 34 | return self.input |
| 35 | |
| 36 | def get_current_errors(self): |
| 37 | return {} |
| 38 | |
| 39 | def save(self, label): |
| 40 | pass |
| 41 | |
| 42 | # helper saving function that can be used by subclasses |
| 43 | def save_network(self, network, network_label, epoch_label, gpu_ids): |
| 44 | save_filename = '%s_net_%s.pth' % (epoch_label, network_label) |
| 45 | save_path = os.path.join(self.save_dir, save_filename) |
| 46 | torch.save(network.cpu().state_dict(), save_path) |
| 47 | if len(gpu_ids) and torch.cuda.is_available(): |
| 48 | network.cuda(gpu_ids[0]) |
| 49 | |
| 50 | def resolve_version(self): |
| 51 | import torch._utils |
| 52 | try: |
| 53 | torch._utils._rebuild_tensor_v2 |
| 54 | except AttributeError: |
| 55 | def _rebuild_tensor_v2(storage, storage_offset, size, stride, requires_grad, backward_hooks): |
| 56 | tensor = torch._utils._rebuild_tensor(storage, storage_offset, size, stride) |
| 57 | tensor.requires_grad = requires_grad |
| 58 | tensor._backward_hooks = backward_hooks |
| 59 | return tensor |
| 60 | torch._utils._rebuild_tensor_v2 = _rebuild_tensor_v2 |
| 61 | |
| 62 | # helper loading function that can be used by subclasses |
| 63 | def load_network(self, network, network_label, epoch_label, save_dir=''): |
nothing calls this directly
no outgoing calls
no test coverage detected