def export_onnx(args):
    model_name = args.model
    if (model_name in models.model_zoo):
        (model, args) = models.get_model(args)
    else:
        print(('model(%s) not support, available models: %r' % (model_name, models.model_zoo)))
        return
    if utils.check_file(args.old):
        print(('load pretrained from %s' % args.old))
        if torch.cuda.is_available():
            checkpoint = torch.load(args.old)
        else:
            checkpoint = torch.load(args.old, map_location='cpu')
        print(('load pretrained ==> last epoch: %d' % checkpoint.get('epoch', 0)))
        print(('load pretrained ==> last best_acc: %f' % checkpoint.get('best_acc', 0)))
        print(('load pretrained ==> last learning_rate: %f' % checkpoint.get('learning_rate', 0)))
        try:
            utils.load_state_dict(model, checkpoint.get('state_dict', None))
        except RuntimeError:
            print('Loading pretrained model failed')
    else:
        print('no pretrained file exists({}), init model with default initlizer'.format(args.old))
    onnx_model = torch.nn.Sequential(OrderedDict([('network', model), ('softmax', torch.nn.Softmax())]))
    onnx_path = ('onnx/' + model_name)
    if (not os.path.exists(onnx_path)):
        os.makedirs(onnx_path)
    onnx_save = (((onnx_path + '/') + model_name) + '.onnx')
    input_names = ['input']
    dummy_input = torch.zeros((1, 3, args.input_size, args.input_size))
    output_names = ['prob']
    torch.onnx.export(onnx_model, dummy_input, onnx_save, verbose=True, input_names=input_names, output_names=output_names, opset_version=7, keep_initializers_as_inputs=True)
def export_onnx(args):
    model_name = args.model
    if (model_name in models.model_zoo):
        (model, args) = models.get_model(args)
    else:
        print(('model(%s) not support, available models: %r' % (model_name, models.model_zoo)))
        return
    if utils.check_file(args.old):
        print(('load pretrained from %s' % args.old))
        if torch.cuda.is_available():
            checkpoint = torch.load(args.old)
        else:
            checkpoint = torch.load(args.old, map_location='cpu')
        print(('load pretrained ==> last epoch: %d' % checkpoint.get('epoch', 0)))
        print(('load pretrained ==> last best_acc: %f' % checkpoint.get('best_acc', 0)))
        print(('load pretrained ==> last learning_rate: %f' % checkpoint.get('learning_rate', 0)))
        try:
            utils.load_state_dict(model, checkpoint.get('state_dict', None))
        except RuntimeError:
            print('Loading pretrained model failed')
    else:
        print('no pretrained file exists({}), init model with default initlizer'.format(args.old))
    onnx_model = torch.nn.Sequential(OrderedDict([('network', model), ('softmax', torch.nn.Softmax())]))
    onnx_path = ('onnx/' + model_name)
    if (not os.path.exists(onnx_path)):
        os.makedirs(onnx_path)
    onnx_save = (((onnx_path + '/') + model_name) + '.onnx')
    input_names = ['input']
    dummy_input = torch.zeros((1, 3, args.input_size, args.input_size))
    output_names = ['prob']
    torch.onnx.export(onnx_model, dummy_input, onnx_save, verbose=True, input_names=input_names, output_names=output_names, opset_version=7, keep_initializers_as_inputs=True)