Skip to content

Commit d6f653e

Browse files
authored
Merge pull request #136 from johnolafenwa/john/newer-gpu-support
Added Support for Newer GPUS
2 parents a2fbc57 + 3d391ab commit d6f653e

8 files changed

Lines changed: 37 additions & 24 deletions

File tree

Dockerfile.cpu

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM deepquestai/deepstack-base:cpu-412378893 as cpu
1+
FROM deepquestai/deepstack-base:cpu-1647248158 as cpu
22

33
ENV SLEEP_TIME 0.01
44
ENV CUDA_MODE False

Dockerfile.gpu

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM deepquestai/deepstack-base:gpu-412378893 as gpu
1+
FROM deepquestai/deepstack-base:gpu-1647248158 as gpu
22

33
ENV SLEEP_TIME 0.01
44
ENV CUDA_MODE True

intelligencelayer/shared/models/common.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import torch
55
import torch.nn as nn
66
from utils.general import non_max_suppression
7-
7+
import torch.nn.functional as F
88

99
def autopad(k, p=None): # kernel, padding
1010
# Pad to 'same'
@@ -26,7 +26,7 @@ def __init__(
2626
super(Conv, self).__init__()
2727
self.conv = nn.Conv2d(c1, c2, k, s, autopad(k, p), groups=g, bias=False)
2828
self.bn = nn.BatchNorm2d(c2)
29-
self.act = nn.Hardswish() if act else nn.Identity()
29+
self.act = Hardswish() if act else nn.Identity()
3030

3131
def forward(self, x):
3232
return self.act(self.bn(self.conv(x)))

intelligencelayer/shared/process.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import shutil
55
import time
66
from pathlib import Path
7-
7+
import models
88
import numpy as np
99
import torch
1010
import torch.backends.cudnn as cudnn
@@ -23,7 +23,8 @@
2323
xyxy2xywh,
2424
)
2525
from utils.torch_utils import load_classifier, select_device, time_synchronized
26-
26+
import torch.nn as nn
27+
from utils.activations import Hardswish
2728

2829
class YOLODetector(object):
2930
def __init__(self, model_path: str, reso: int = 640, cuda: bool = False):
@@ -34,6 +35,13 @@ def __init__(self, model_path: str, reso: int = 640, cuda: bool = False):
3435
self.reso = (reso, reso)
3536
self.cuda = cuda
3637
self.model = attempt_load(model_path, map_location=self.device)
38+
39+
# Update model
40+
for k, m in self.model.named_modules():
41+
m._non_persistent_buffers_set = set() # pytorch 1.6.0 compatability
42+
if isinstance(m, models.common.Conv) and isinstance(m.act, nn.Hardswish):
43+
m.act = Hardswish() # assign activation
44+
3745
self.names = (
3846
self.model.module.names
3947
if hasattr(self.model, "module")

intelligencelayer/shared/utils/activations.py

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,29 @@ class Swish(nn.Module): #
99
def forward(x):
1010
return x * torch.sigmoid(x)
1111

12-
13-
class Hardswish(nn.Module): # export-friendly version of nn.Hardswish()
14-
@staticmethod
15-
def forward(x):
16-
# return x * F.hardsigmoid(x) # for torchscript and CoreML
17-
return x * F.hardtanh(x + 3, 0.0, 6.0) / 6.0 # for torchscript, CoreML and ONNX
18-
12+
class Hardswish(nn.Module):
13+
r"""Applies the hardswish function, element-wise, as described in the paper:
14+
`Searching for MobileNetV3`_.
15+
.. math::
16+
\text{Hardswish}(x) = \begin{cases}
17+
0 & \text{if~} x \le -3, \\
18+
x & \text{if~} x \ge +3, \\
19+
x \cdot (x + 3) /6 & \text{otherwise}
20+
\end{cases}
21+
Shape:
22+
- Input: :math:`(N, *)` where `*` means, any number of additional
23+
dimensions
24+
- Output: :math:`(N, *)`, same shape as the input
25+
Examples::
26+
>>> m = nn.Hardswish()
27+
>>> input = torch.randn(2)
28+
>>> output = m(input)
29+
.. _`Searching for MobileNetV3`:
30+
https://arxiv.org/abs/1905.02244
31+
"""
32+
33+
def forward(self, input: torch.Tensor) -> torch.Tensor:
34+
return F.hardswish(input)
1935

2036
class MemoryEfficientSwish(nn.Module):
2137
class F(torch.autograd.Function):

logs/stderr.txt

Lines changed: 0 additions & 8 deletions
This file was deleted.

logs/stdout.txt

Lines changed: 0 additions & 3 deletions
This file was deleted.

server/endpoints/endpoints.go

Whitespace-only changes.

0 commit comments

Comments
 (0)