Cong Wang commited on
Commit ·
092da5b
1
Parent(s): 3e9404f
Support safeensors.
Browse files1234567850 unmodified lines5960616263646566import torchimport yamlfrom peaknet.modeling.convnextv2_bifpn_net import PeakNet, PeakNetConfig, SegHeadConfigfrom peaknet.modeling.bifpn_config import BiFPNConfig, BiFPNBlockConfig, BNConfig, FusionConfigfrom transformers.models.convnextv2.configuration_convnextv2 import ConvNextV2Configfrom contextlib import nullcontextclass PeakNetInference:50 unmodified linesreturn PeakNet(peaknet_config)def _load_weights(self, weights_path):weights = torch.load(weights_path, map_location='cpu')self.model.load_state_dict(weights)def predict(self, input_tensor):with torch.no_grad():1234567891050 unmodified lines616263646566676869707172import osimport torchimport yamlfrom peaknet.modeling.convnextv2_bifpn_net import PeakNet, PeakNetConfig, SegHeadConfigfrom peaknet.modeling.bifpn_config import BiFPNConfig, BiFPNBlockConfig, BNConfig, FusionConfigfrom transformers.models.convnextv2.configuration_convnextv2 import ConvNextV2Configfrom safetensors.torch import load_file as load_safetensorsfrom contextlib import nullcontextclass PeakNetInference:50 unmodified linesreturn PeakNet(peaknet_config)def _load_weights(self, weights_path):_, extension = os.path.splitext(weights_path)if extension == '.safetensors':state_dict = load_safetensors(weights_path)else:state_dict = torch.load(weights_path, map_location='cpu')self.model.load_state_dict(state_dict)def predict(self, input_tensor):with torch.no_grad():
peaknet_inference/__init__.py+8-2