def initialize(self): if isinstance(self.pool_stride, int) and self.pool_stride == 1: self.pool_stride = [1] * len(self.output_layers) self.layer_stride = {'vggconv1': 2, 'conv1': 2, 'layer1': 4, 'layer2': 8, 'layer3': 16, 'layer4': 32, 'fc': None} self.layer_dim = {'vggconv1': 96, 'conv1': 64, 'layer1': 64, 'layer2': 128, 'layer3': 256, 'layer4': 512, 'fc': None} self.mean = torch.Tensor([0.485, 0.456, 0.406]).view(1, -1, 1, 1) self.std = torch.Tensor([0.229, 0.224, 0.225]).view(1, -1, 1, 1) if os.path.isabs(self.net_path): net_path_full = [self.net_path] else: root_paths = env_settings().network_path if isinstance(root_paths, str): root_paths = [root_paths] net_path_full = [os.path.join(root, self.net_path) for root in root_paths] self.net = None for net_path in net_path_full: try: self.net = resnet18_vggmconv1(self.output_layers, path=net_path) break except: pass if self.net is None: raise Exception('Did not find network file {}'.format(self.net_path)) if self.use_gpu: self.net.cuda() self.net.eval()
def initialize(self, im): if os.path.isabs(self.net_path): net_path_full = self.net_path else: net_path_full = os.path.join(env_settings().network_path, self.net_path) if isinstance(self.pool_stride, int) and self.pool_stride == 1: self.pool_stride = [1] * len(self.output_layers) self.layer_stride = { 'vggconv1': 2, 'conv1': 2, 'layer1': 4, 'layer2': 8, 'layer3': 16, 'layer4': 32, 'fc': None } self.layer_dim = { 'vggconv1': 96, 'conv1': 64, 'layer1': 64, 'layer2': 128, 'layer3': 256, 'layer4': 512, 'fc': None } #self.mean = torch.Tensor([0.485, 0.456, 0.406]).view(1,-1,1,1) #self.std = torch.Tensor([0.229, 0.224, 0.225]).view(1,-1,1,1) im = im / 255 self.mean = torch.Tensor([ torch.mean(im[:, 0, ...]), torch.mean(im[:, 1, ...]), torch.mean(im[:, 2, ...]) ]).view(1, -1, 1, 1) self.std = torch.Tensor([ torch.std(im[:, 0, ...]), torch.std(im[:, 1, ...]), torch.std(im[:, 2, ...]) ]).view(1, -1, 1, 1) self.net = resnet18_vggmconv1(self.output_layers, path=net_path_full) if self.use_gpu: self.net.cuda(self.gpu_device) if not ( self.gpu_device is None) else self.net.cuda() self.net.eval()