Example #1
0
"""BLPose Test: VGG

Author: Bo Lin (@linbo0518)
Date: 2020-12-07
"""

import sys
import torch
from test import test_backbone

sys.path.append("../")
from blpose.utils.profiler import Profiler
from blpose.backbones.vgg import *

p = Profiler()
x = torch.randn(8, 3, 224, 224, dtype=torch.float32)

net = VGG11()
with p.profiling("Test VGG11"):
    test_backbone(net, x, 8, 16)

net = VGG13()
with p.profiling("Test VGG13"):
    test_backbone(net, x, 8, 16)

net = VGG16()
with p.profiling("Test VGG16"):
    test_backbone(net, x, 8, 16)

net = VGG19()
with p.profiling("Test VGG19"):
Example #2
0
"""BLPose Test: Train Dataset

Author: Bo Lin (@linbo0518)
Date: 2021-01-03
"""

import sys
import matplotlib.pyplot as plt

sys.path.append("../")
from blpose.train.dataset import COCOKeypoints, COCOUtils
from blpose.utils.profiler import Profiler

p = Profiler()

coco_dir = "/Users/linbo0518/Movies/COCO2017"
coco_keypoints = COCOKeypoints(coco_dir)

with p.profiling("Test COCO Keypoints API"):
    image, keypoints_all, mask_all, mask_loss, anno = coco_keypoints[0]

plt.imshow(image[:, :, ::-1])
plt.axis("off")
plt.show()

plt.imshow(mask_loss, cmap="hot")
plt.axis("off")
plt.show()

offset = 0
for idx, keypoints in enumerate(keypoints_all):
Example #3
0
"""BLPose Test: Utils Layers

Author: Bo Lin (@linbo0518)
Date: 2020-12-08
"""

import sys
from torch import nn

sys.path.append("../")
from blpose.utils.profiler import Profiler
from blpose.utils.layers import *

p = Profiler()

with p.profiling("Test get_conv1x1"):
    print(f"ref: {nn.Conv2d(3, 64, kernel_size=1, stride=1, bias=False)}")
    print(f"act: {get_conv1x1(3, 64, stride=1)}")

    print(f"ref: {nn.Conv2d(64, 128, kernel_size=1, stride=2, bias=False)}")
    print(f"act: {get_conv1x1(64, 128, stride=2)}")

with p.profiling("Test get_conv3x3"):
    print(
        f"ref: {nn.Conv2d(3, 64, kernel_size=3, stride=1, padding=1, bias=False)}"
    )
    print(f"act: {get_conv3x3(3, 64, stride=1)}")

    print(
        f"ref: {nn.Conv2d(64, 128, kernel_size=3, stride=2, padding=1, bias=False)}"
    )
Example #4
0
"""BLPose Test: OpenPose

Author: Bo Lin (@linbo0518)
Date: 2020-12-11
"""

import sys
import torch

sys.path.append("../")
from blpose.utils.profiler import Profiler
from blpose.estimators.openpose import *

p = Profiler()

x = torch.randn(8, 3, 368, 368)

net = OpenPoseV1(19, 18)
with p.profiling("Test OpenPose v1"):
    y = net(x)
print(f"Input shape: {x.shape}, Output shape: {y[0].shape}, {y[1].shape}")
torch.onnx.export(net, x, "outputs/openpose_v1.onnx", opset_version=11)

net = OpenPoseV2(19, 18)
with p.profiling("Test OpenPose v2"):
    y = net(x)
print(f"Input shape: {x.shape}, Output shape: {y[0].shape}, {y[1].shape}")
torch.onnx.export(net, x, "outputs/openpose_v2.onnx", opset_version=11)
Example #5
0
"""BLPose Test: Pose Machine

Author: Bo Lin (@linbo0518)
Date: 2020-12-15
"""

import sys
import cv2
import matplotlib.pyplot as plt

sys.path.append("../")
from blpose.utils.profiler import Profiler
from blpose.estimators import OpenPoseV1
from blpose import PoseMachine

p = Profiler()
pose_machine = PoseMachine(OpenPoseV1(19, 18), "../models/openpose_v1_coco.pt",
                           "cpu")

with p.profiling("Test Pose Machine"):
    x = cv2.imread("assets/ski.jpg")
    candidate, bodies = pose_machine.image_predict(x)
    canvas = pose_machine.draw_pose(x, candidate, bodies)

print(candidate)
print(bodies)
plt.imshow(cv2.cvtColor(canvas, cv2.COLOR_BGR2RGB))
plt.show()
Example #6
0
"""BLPose Test: MobileNet

Author: Bo Lin (@linbo0518)
Date: 2020-12-29
"""

import sys
import torch
from test import test_backbone

sys.path.append("../")
from blpose.utils.profiler import Profiler
from blpose.backbones.mobilenet import *

p = Profiler()
x = torch.randn(8, 3, 224, 224)

net = MobileNetV1()
with p.profiling("Test MobileNet v1"):
    test_backbone(net, x, 8, 16, 32)

net = MobileNetV2()
with p.profiling("Test MobileNet v2"):
    test_backbone(net, x, 8, 16, 32)
Example #7
0
"""BLPose Test: ResNet

Author: Bo Lin (@linbo0518)
Date: 2020-12-08
"""

import sys
import torch
from test import test_backbone

sys.path.append("../")
from blpose.utils.profiler import Profiler
from blpose.backbones.resnet import *

p = Profiler()
x = torch.randn(8, 3, 224, 224, dtype=torch.float32)

net = ResNet18()
with p.profiling("Test ResNet18"):
    test_backbone(net, x, 8, 16, 32)

net = ResNet34()
with p.profiling("Test ResNet34"):
    test_backbone(net, x, 8, 16, 32)

net = ResNet50()
with p.profiling("Test ResNet50"):
    test_backbone(net, x, 8, 16, 32)

net = ResNet101()
with p.profiling("Test ResNet101"):
Example #8
0
"""BLPose Test: Test Stacked Hourglass

Author: Bo Lin (@linbo0518)
Date: 2020-12-23
"""

import sys
import torch

sys.path.append("../")
from blpose.utils.profiler import Profiler
from blpose.estimators.hourglass import Hourglass, StackedHourglass

p = Profiler()

x = torch.randn(1, 256, 256, 256)
net = Hourglass(4, 256)
with p.profiling("Test Hourglass"):
    y = net(x)
print(f"Input shape: {x.shape}, Output shape: {y.shape}")
torch.onnx.export(net, x, "outputs/hourglass.onnx", opset_version=11)

x = torch.randn(1, 3, 256, 256)
net = StackedHourglass(n_keypoints=15)
with p.profiling("Test Stacked Hourglass"):
    y = net(x)
print(f"Input shape: {x.shape}, Output shape: {y.shape}")
torch.onnx.export(net, x, "outputs/stacked_hourglass.onnx", opset_version=11)
Example #9
0
"""BLPose Test: SE ResNet

Author: Bo Lin (@linbo0518)
Date: 2020-12-09
"""

import sys
import torch
from test import test_backbone

sys.path.append("../")
from blpose.utils.profiler import Profiler
from blpose.backbones.seresnet import *

p = Profiler()
x = torch.randn(8, 3, 224, 224, dtype=torch.float32)

net = SEResNet50()
with p.profiling("Test SEResNet50"):
    test_backbone(net, x, 8, 16, 32)

net = SEResNet101()
with p.profiling("Test SEResNet101"):
    test_backbone(net, x, 8, 16, 32)

net = SEResNet152()
with p.profiling("Test SEResNet152"):
    test_backbone(net, x, 8, 16, 32)