This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def swa(paths): | |
state_dicts = [] | |
for path in paths: | |
state_dicts.append(torch.load(path)["model_state_dict"]) | |
average_dict = OrderedDict() | |
for k in state_dicts[0].keys(): | |
average_dict[k] = sum([state_dict[k] for state_dict in state_dicts]) / len(state_dicts) | |
return average_dict |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ArcModule(nn.Module): | |
def __init__(self, in_features, out_features, s=10, m=0.5): | |
super().__init__() | |
self.in_features = in_features | |
self.out_features = out_features | |
self.s = s | |
self.m = m | |
self.weight = nn.Parameter(torch.FloatTensor(out_features, in_features)) | |
nn.init.xavier_normal_(self.weight) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import onnx | |
import torch | |
import torch.nn as nn | |
import onnxruntime as ort | |
from onnxsim import simplify | |
from PIL import Image | |
from ssd.config import cfg | |
from ssd.data.datasets import COCODataset, VOCDataset | |
import argparse |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import onnx | |
import torch | |
import torchvision | |
import onnxruntime as ort | |
from onnxsim import simplify | |
import numpy as np | |
if __name__ == '__main__': | |
model = torchvision.models.resnet18(pretrained=True).cuda().eval() | |
dummy_input = torch.ones(1, 3, 224, 224, device="cuda") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import utils.inference as inference_utils # TRT/TF inference wrappers | |
import utils.model as model_utils # UFF conversion | |
import tensorrt as trt | |
import argparse | |
if __name__ == '__main__': | |
parser = argparse.ArgumentParser(description='TRT params') | |
parser.add_argument('--FP', default="32", type=str) | |
args = parser.parse_args() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import onnx | |
import torch | |
import numpy as np | |
import onnxruntime as ort | |
import torchvision as tv | |
from onnxsim import simplify | |
dummy_input = torch.ones(1, 3, 300, 300, device="cuda") | |
pt_model_det = tv.models.resnet50().cuda().eval().requires_grad_(False) | |
pre_det_res = pt_model_det(dummy_input.cuda()) | |
print(f"Torch output shape: {pre_det_res.shape}") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import onnx | |
import torch | |
import torch.nn as nn | |
import torchvision | |
import torchvision.transforms as transforms | |
#import cv2 | |
from PIL import Image | |
import os | |
import matplotlib.pyplot as plt | |
import time |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from caffe2.proto import caffe2_pb2 | |
from caffe2.python import core, workspace | |
from detectron2.export.caffe2_inference import ProtobufDetectionModel | |
from detectron2.export.api import Caffe2Model | |
import numpy as np | |
import os | |
import torch | |
import cv2 | |
import time | |
import shutil |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from caffe2.proto import caffe2_pb2 | |
from caffe2.python import core, workspace | |
from detectron2.export.caffe2_inference import ProtobufDetectionModel | |
from detectron2.export.api import Caffe2Model | |
import numpy as np | |
import os | |
import torch | |
import cv2 | |
print("Required modules imported.") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from flask import Flask, request, jsonify | |
server = Flask(__name__) | |
def run_request(): | |
index = int(request.json['index']) | |
list = ['red', 'green', 'blue', 'yellow', 'black'] | |
return list[index] | |
@server.route('/', methods=['GET', 'POST']) |
NewerOlder