def resNet152Test(): net = loadResNet(modelpath="../TestData/ResNet-152-model.hdf", layers="152") sample = loadResNetSample(net, "../TestData/tarantula.jpg") labels = loadLabels(synpath="../TestData/synsets.txt", wordpath="../TestData/synset_words.txt") res = net(gpuarray.to_gpu(sample)).get().reshape(-1) showLabelResults(res, labels, header=net.name)
def main(): net = loadNiNImageNet(modelpath="../TestData/nin_imagenet.hdf") sample = loadSample("../TestData/barometer.jpg") labels = loadLabels(synpath="../TestData/synsets.txt", wordpath="../TestData/synset_words.txt") res = net(gpuarray.to_gpu(sample)).get().reshape(-1) showLabelResults(res, labels, header="NiN")
def inceptionBNTest(): net = loadInceptionBN(modelpath="../TestData/Inception-BN-0126.hdf") sample = loadVGGSample("../TestData/tarantula.jpg") labels = loadLabels(synpath="../TestData/synsets.txt", wordpath="../TestData/synset_words.txt") res = net(gpuarray.to_gpu(sample)).get().reshape(-1) showLabelResults(res, labels, header=net.name)
def main(): net = loadResNet(modelpath="../../TestData/ResNet-50-model.hdf", layers="50") data = gpuarray.to_gpu(loadResNetSample(net, "../../TestData/tarantula.jpg")) labels = loadLabels(synpath="../../TestData/synsets.txt", wordpath="../../TestData/synset_words.txt") engine = buildRTEngine(net, inshape=data.shape, savepath="../TestData", dtype=DataType.float32) scoreModels(net, engine, data, labels) benchModels(net, engine, data)
def vgg19Test(): net = loadVGG(modelpath="../TestData/VGG_ILSVRC_19_layers.hdf", layers="19") sample = loadVGGSample("../TestData/tarantula.jpg") labels = loadLabels(synpath="../TestData/synsets.txt", wordpath="../TestData/synset_words.txt") res = net(gpuarray.to_gpu(sample)).get().reshape(-1) showLabelResults(res, labels, header=net.name)
def main(): inshape = (1, 3, 224, 224) net = loadResNet(modelpath="../../TestData/ResNet-50-model.hdf", layers="50") outshape = net.dataShapeFrom(inshape) caffeengine = buildRTEngineFromCaffe( ("../TestData/ResNet-50-deploy.prototxt", "../TestData/ResNet-50-model.caffemodel"), inshape=inshape, outshape=outshape, outlayers=["prob"], dtype=DataType.float32, savepath="../TestData") onnxengine = buildRTEngineFromOnnx("../TestData/resnet50.onnx", inshape=inshape, outshape=outshape, dtype=DataType.float32, savepath="../TestData") data = gpuarray.to_gpu( loadResNetSample(net, "../../TestData/tarantula.jpg")) labels = loadLabels(synpath="../../TestData/synsets.txt", wordpath="../../TestData/synset_words.txt") netData = net(data).get() caffeData = caffeengine(data).get() data = np.moveaxis( np.array(Image.open("../../TestData/tarantula.jpg"), dtype=np.float32), 2, 0) data = gpuarray.to_gpu(preprocessCaffe2Onnx(data)[np.newaxis, ...]) onnxData = onnxengine(data).get() printResults(netData, labels, "Net") printResults(caffeData, labels, "Caffe") printResults(onnxData, labels, "Onnx")