else: pred_outs['conf'] = F.softmax(pred_outs['conf'], -1) return self.detect(pred_outs) # Some testing code if __name__ == '__main__': from utils.functions import init_console init_console() # Use the first argument to set the config if you want import sys if len(sys.argv) > 1: from data.config import set_cfg set_cfg(sys.argv[1]) net = Yolact() net.train() net.init_weights(backbone_path='weights/' + cfg.backbone.path) # GPU # net = net.cuda() net = net # cudnn.benchmark = True torch.set_default_tensor_type('torch.FloatTensor') x = torch.zeros((1, 3, cfg.max_size, cfg.max_size)) y = net(x) for p in net.prediction_layers:
# Copyright (c) 2020 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. from data.config import set_cfg from yolact import Yolact set_cfg('yolact_resnet50_config') def create_model(weights): yolact = Yolact() yolact.load_weights(weights) return yolact
#pub = rospy.Publisher('chatter',String,queue_size=10) #rate = rospy.Rate(50) #10hz #str_ += text_str #rospy.loginfo(str_) #pub.publish(str_) #rate.sleep() return img_numpy if __name__ == '__main__': parse_args() if args.config is not None: set_cfg(args.config) if args.trained_model == 'interrupt': args.trained_model = SavePath.get_interrupt('weights/') elif args.trained_model == 'latest': args.trained_model = SavePath.get_latest('weights/', cfg.name) if args.config is None: model_path = SavePath.from_str(args.trained_model) # TODO: Bad practice? Probably want to do a name lookup instead. args.config = model_path.model_name + '_config' print('Config not specified. Parsed %s from the file name.\n' % args.config) set_cfg(args.config) if args.detect:
iou_thresholds = [x / 100 for x in range(50, 100, 5)] cuda = torch.cuda.is_available() if __name__ == '__main__': args = parser.parse_args() json_path = 'results' if not os.path.exists(json_path): os.mkdir(json_path) if args.config is None: piece = args.trained_model.split('/')[1].split('_') name = f'{piece[0]}_{piece[1]}_config' print( f'\nConfig not specified. Parsed \'{name}\' from the checkpoint name.\n' ) set_cfg(name) with torch.no_grad(): if cuda: cudnn.benchmark = True cudnn.fastest = True torch.set_default_tensor_type('torch.cuda.FloatTensor') else: torch.set_default_tensor_type('torch.FloatTensor') dataset = COCODetection(cfg.dataset.valid_images, cfg.dataset.valid_info, augmentation=BaseTransform()) print('Loading model...') net = Yolact()