Skip to content

Commit

Permalink
Merge pull request #83 from johnolafenwa/johnolafenwa/windows
Browse files Browse the repository at this point in the history
Johnolafenwa/windows
  • Loading branch information
johnolafenwa authored Feb 5, 2021
2 parents ff66441 + c9bc615 commit 583c622
Show file tree
Hide file tree
Showing 17 changed files with 244 additions and 22 deletions.
40 changes: 38 additions & 2 deletions .github/workflows/pr_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ on:
- dev
- master
jobs:
build:
docker-build:
runs-on: ubuntu-20.04
steps:
- name: Checkout repo
Expand Down Expand Up @@ -72,4 +72,40 @@ jobs:
export TEST_DEEPSTACK_URL="http://localhost:80"
cd custom
python3 -m pytest
sudo docker container rm -f deepstack
sudo docker container rm -f deepstack
windows-build:
runs-on: windows-2019
steps:
- name: Checkout repo
uses: actions/checkout@master
- name: Fetch GIT LFS
run: git lfs checkout && git lfs pull
- name: Install python
uses: actions/setup-python@v2
with:
python-version: "3.7"
- name: Install Pytest and Requests
run: pip install pytest requests
- name: Setup Golang
uses: actions/setup-go@v2
- name: Build DeepStack Go Component
run: cd server && go build -o deepstack.exe
- name: Generate CPU Build Script
run: .\generate_windows_setup.ps1 -Platform CPU -Version 1.0
- name: Build CPU Version
run: .\build_windows.ps1
- name: Install DeepStack CPU Version
run: |
$deepstack_installer = [System.IO.Directory]::GetCurrentDirectory()+"\Output\DeepStack-Installer-CPU.exe"
Start-Process -FilePath $deepstack_installer -ArgumentList "/VERYSILENT" -Wait -NoNewWindow
- name: Test Scene
run: |
cd tests
$ErrorActionPreference = "Stop"
$env:TEST_DATA_DIR=[System.IO.Directory]::GetCurrentDirectory()+"\tests\test_data"
$env:TEST_DEEPSTACK_URL="http://localhost:80"
Start-Process -FilePath "C:\DeepStack\deepstack.exe" -ArgumentList "--PORT 80" -NoNewWindow
Start-Sleep 30
cd scene
python -m pytest
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ __pycache__/
*.py[cod]
*$py.class

*.err
*.out
*.iss
!environment.iss

# C extensions
*.so

Expand Down
42 changes: 42 additions & 0 deletions Dockerfile.arm64
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
FROM deepquestai/deepstack-base:arm64 as arm

ENV SLEEP_TIME 0.01
ENV CUDA_MODE False
ENV APPDIR /app

RUN mkdir /deeptemp
RUN mkdir /datastore

ENV DATA_DIR /datastore
ENV TEMP_PATH /deeptemp/
ENV PROFILE jetson

WORKDIR /app

RUN pip3 install redis
RUN pip3 install Cython
RUN pip3 install pillow
RUN pip3 install scipy
RUN pip3 install tqdm
RUN pip3 install PyYAML

RUN mkdir /app/sharedfiles
COPY ./sharedfiles/yolov5s.pt /app/sharedfiles/yolov5s.pt
COPY ./sharedfiles/face_lite.pt /app/sharedfiles/face_lite.pt
COPY ./sharedfiles/facerec-high.model /app/sharedfiles/facerec-high.model
COPY ./sharedfiles/scene.pt /app/sharedfiles/scene.pt
COPY ./sharedfiles/categories_places365.txt /app/sharedfiles/categories_places365.txt

RUN mkdir /app/server
COPY ./server /app/server

RUN mkdir /app/intelligencelayer
COPY ./intelligencelayer /app/intelligencelayer

COPY ./init.py /app

EXPOSE 5000

WORKDIR /app/server

CMD ["/app/server/server"]
2 changes: 1 addition & 1 deletion Dockerfile.cpu
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ RUN mkdir /app/sharedfiles
COPY ./sharedfiles/yolov5m.pt /app/sharedfiles/yolov5m.pt
COPY ./sharedfiles/face.pt /app/sharedfiles/face.pt
COPY ./sharedfiles/facerec-high.model /app/sharedfiles/facerec-high.model
COPY ./sharedfiles/scene.model /app/sharedfiles/scene.model
COPY ./sharedfiles/scene.pt /app/sharedfiles/scene.pt
COPY ./sharedfiles/categories_places365.txt /app/sharedfiles/categories_places365.txt

RUN mkdir /app/server
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile.gpu
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ RUN mkdir /app/sharedfiles
COPY ./sharedfiles/yolov5m.pt /app/sharedfiles/yolov5m.pt
COPY ./sharedfiles/face.pt /app/sharedfiles/face.pt
COPY ./sharedfiles/facerec-high.model /app/sharedfiles/facerec-high.model
COPY ./sharedfiles/scene.model /app/sharedfiles/scene.model
COPY ./sharedfiles/scene.pt /app/sharedfiles/scene.pt
COPY ./sharedfiles/categories_places365.txt /app/sharedfiles/categories_places365.txt

RUN mkdir /app/server
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile.gpu-jetpack
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ RUN mkdir /app/sharedfiles
COPY ./sharedfiles/yolov5s.pt /app/sharedfiles/yolov5s.pt
COPY ./sharedfiles/face_lite.pt /app/sharedfiles/face_lite.pt
COPY ./sharedfiles/facerec-high.model /app/sharedfiles/facerec-high.model
COPY ./sharedfiles/scene.model /app/sharedfiles/scene.model
COPY ./sharedfiles/scene.pt /app/sharedfiles/scene.pt
COPY ./sharedfiles/categories_places365.txt /app/sharedfiles/categories_places365.txt

RUN mkdir /app/server
Expand Down
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@
The World's Leading Cross Platform AI Engine for Edge Devices, with over `3.2 million` installs on **Docker Hub**.

[![black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
[![license](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](hhttps://github.com/johnolafenwa/DeepStack/blob/dev/LICENSE)

[![license](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](hhttps://github.com/johnolafenwa/DeepStack/blob/dev/LICENSE)

![DevTest](https://github.com/johnolafenwa/DeepStack/workflows/DevTest/badge.svg)

**Website**: [https://deepstack.cc](https://deepstack.cc)

**Documentation**: [https://docs.deepstack.cc](https://docs.deepstack.cc)
Expand Down
2 changes: 2 additions & 0 deletions build_windows.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
$ErrorActionPreference = "Stop"
Start-Process -FilePath "windows_setup/ISCC.exe" -ArgumentList "deepstack-windows.iss" -Wait -NoNewWindow
115 changes: 115 additions & 0 deletions generate_windows_setup.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
param(
[ValidateSet("CPU","GPU")]
[Parameter(Mandatory=$true)]
[string]$Platform,

[Parameter(Mandatory=$true)]
[string]$Version
)

$ErrorActionPreference = "Stop"

$setup_script = "#include ""environment.iss"""
$setup_script += "`n#define MyAppName ""DeepStack"""
$setup_script += "`n#define MyAppVersion ""$Version"""
$setup_script += "`n#define MyAppPublisher ""DeepQuestAI"""
$setup_script += "`n#define MyAppURL ""https://www.deepstack.cc"""
$setup_script += "`n#define MyAppExeName ""deepstack.exe"""
$setup_script += "`n#define MyAppIcon ""logo.ico"""

$setup_script += "`n`n[Setup]"
$setup_script += "`nChangesEnvironment=true"
$setup_script += "`nAppId={{0E2C3125-3440-4622-A82A-3B1E07310EF2}"
$setup_script += "`nAppName={#MyAppName}"
$setup_script += "`nAppVersion={#MyAppVersion}"
$setup_script += "`nAppPublisher={#MyAppPublisher}"
$setup_script += "`nAppPublisherURL={#MyAppURL}"
$setup_script += "`nAppSupportURL={#MyAppURL}"
$setup_script += "`nAppUpdatesURL={#MyAppURL}"
$setup_script += "`nDefaultDirName=C:\{#MyAppName}"
$setup_script += "`nDisableDirPage=yes"
$setup_script += "`nDefaultGroupName=DeepStack"
$setup_script += "`nOutputBaseFilename=DeepStack-Installer-$Platform"
$setup_script += "`nCompression=lzma"
$setup_script += "`nSolidCompression=yes"

$setup_script += "`n`n[Languages]"
$setup_script += "`nName: ""english""; MessagesFile: ""compiler:Default.isl"""
$setup_script += "`nName: ""armenian""; MessagesFile: ""compiler:Languages\Armenian.isl"""
$setup_script += "`nName: ""brazilianportuguese""; MessagesFile: ""compiler:Languages\BrazilianPortuguese.isl"""
$setup_script += "`nName: ""catalan""; MessagesFile: ""compiler:Languages\Catalan.isl"""
$setup_script += "`nName: ""corsican""; MessagesFile: ""compiler:Languages\Corsican.isl"""
$setup_script += "`nName: ""czech""; MessagesFile: ""compiler:Languages\Czech.isl"""
$setup_script += "`nName: ""danish""; MessagesFile: ""compiler:Languages\Danish.isl"""
$setup_script += "`nName: ""dutch""; MessagesFile: ""compiler:Languages\Dutch.isl"""
$setup_script += "`nName: ""finnish""; MessagesFile: ""compiler:Languages\Finnish.isl"""
$setup_script += "`nName: ""french""; MessagesFile: ""compiler:Languages\French.isl"""
$setup_script += "`nName: ""german""; MessagesFile: ""compiler:Languages\German.isl"""
$setup_script += "`nName: ""hebrew""; MessagesFile: ""compiler:Languages\Hebrew.isl"""
$setup_script += "`nName: ""icelandic""; MessagesFile: ""compiler:Languages\Icelandic.isl"""
$setup_script += "`nName: ""italian""; MessagesFile: ""compiler:Languages\Italian.isl"""
$setup_script += "`nName: ""japanese""; MessagesFile: ""compiler:Languages\Japanese.isl"""
$setup_script += "`nName: ""norwegian""; MessagesFile: ""compiler:Languages\Norwegian.isl"""
$setup_script += "`nName: ""polish""; MessagesFile: ""compiler:Languages\Polish.isl"""
$setup_script += "`nName: ""portuguese""; MessagesFile: ""compiler:Languages\Portuguese.isl"""
$setup_script += "`nName: ""russian""; MessagesFile: ""compiler:Languages\Russian.isl"""
$setup_script += "`nName: ""slovak""; MessagesFile: ""compiler:Languages\Slovak.isl"""
$setup_script += "`nName: ""slovenian""; MessagesFile: ""compiler:Languages\Slovenian.isl"""
$setup_script += "`nName: ""spanish""; MessagesFile: ""compiler:Languages\Spanish.isl"""
$setup_script += "`nName: ""turkish""; MessagesFile: ""compiler:Languages\Turkish.isl"""
$setup_script += "`nName: ""ukrainian""; MessagesFile: ""compiler:Languages\Ukrainian.isl"""


$setup_script += "`n`n[Tasks]"
$setup_script += "`nName: ""desktopicon""; Description: ""{cm:CreateDesktopIcon}""; GroupDescription: ""{cm:AdditionalIcons}""; Flags: unchecked"
$setup_script += "`nName: ""quicklaunchicon""; Description: ""{cm:CreateQuickLaunchIcon}""; GroupDescription: ""{cm:AdditionalIcons}""; Flags: unchecked; OnlyBelowVersion: 0,6.1"

$setup_script += "`n`n[Files]"
$setup_script += "`nSource: ""$PSScriptRoot\server\deepstack.exe""; DestDir: ""{app}""; Flags: ignoreversion"
$setup_script += "`nSource: ""$PSScriptRoot\*""; DestDir: ""{app}"";"
$setup_script += "`nSource: ""$PSScriptRoot\intelligencelayer\*""; DestDir: ""{app}\intelligencelayer""; Flags: ignoreversion recursesubdirs createallsubdirs"
$setup_script += "`nSource: ""$PSScriptRoot\interpreter\*""; DestDir: ""{app}\interpreter""; Flags: ignoreversion recursesubdirs createallsubdirs"
$setup_script += "`nSource: ""$PSScriptRoot\redis\*""; DestDir: ""{app}\redis""; Flags: ignoreversion recursesubdirs createallsubdirs"
$setup_script += "`nSource: ""$PSScriptRoot\server\*""; DestDir: ""{app}\server""; Flags: ignoreversion recursesubdirs createallsubdirs"
if($Platform -eq "CPU"){
$setup_script += "`nSource: ""$PSScriptRoot\platform\platform.windows.cpu.json""; DestDir: ""{app}\server""; DestName: ""platform.json""; Flags: ignoreversion"
}
elseif ($Platform -eq "GPU") {
$setup_script += "`nSource: ""$PSScriptRoot\platform\platform.windows.gpu.json""; DestDir: ""{app}\server""; DestName: ""platform.json""; Flags: ignoreversion"
}
$setup_script += "`nSource: ""$PSScriptRoot\server\version.txt""; DestDir: ""{app}\server""; Flags: ignoreversion"
$setup_script += "`nSource: ""$PSScriptRoot\sharedfiles\categories_places365.txt""; DestDir: ""{app}\sharedfiles""; Flags: ignoreversion"
$setup_script += "`nSource: ""$PSScriptRoot\sharedfiles\face.pt""; DestDir: ""{app}\sharedfiles""; Flags: ignoreversion"
$setup_script += "`nSource: ""$PSScriptRoot\sharedfiles\facerec-high.model""; DestDir: ""{app}\sharedfiles""; Flags: ignoreversion"
$setup_script += "`nSource: ""$PSScriptRoot\sharedfiles\scene.pt""; DestDir: ""{app}\sharedfiles""; Flags: ignoreversion"
$setup_script += "`nSource: ""$PSScriptRoot\sharedfiles\yolov5m.pt""; DestDir: ""{app}\sharedfiles""; Flags: ignoreversion"
if($Platform -eq "CPU"){
$setup_script += "`nSource: ""$PSScriptRoot\windows_packages_cpu\*""; DestDir: ""{app}\windows_packages""; Flags: ignoreversion recursesubdirs createallsubdirs"
}
elseif($Platform -eq "GPU"){
$setup_script += "`nSource: ""$PSScriptRoot\windows_packages_gpu\*""; DestDir: ""{app}\windows_packages""; Flags: ignoreversion recursesubdirs createallsubdirs"
}

$setup_script += "`nSource: ""$PSScriptRoot\logo.ico""; DestDir: ""{app}""; Flags: ignoreversion"
$setup_script += "`nSource: ""$PSScriptRoot\init.py""; DestDir: ""{app}""; Flags: ignoreversion"

$setup_script += "`n`n[Icons]"
$setup_script += "`nName: ""{group}\{#MyAppName}""; Filename: ""{app}\{#MyAppExeName}"""
$setup_script += "`nName: ""{group}\{cm:UninstallProgram,{#MyAppName}}""; Filename: ""{uninstallexe}"""
$setup_script += "`nName: ""{commondesktop}\{#MyAppName}""; Filename: ""{app}\{#MyAppExeName}""; IconFilename: {app}\{#MyAppIcon}; Tasks: desktopicon quicklaunchicon"
$setup_script += "`nName: ""{userappdata}\Microsoft\Internet Explorer\Quick Launch\{#MyAppName}""; Filename: ""{app}\{#MyAppExeName}""; IconFilename: {app}\{#MyAppIcon}; Tasks: quicklaunchicon"

$setup_script += "`n[Code]"
$setup_script += "`nprocedure CurStepChanged(CurStep: TSetupStep);"
$setup_script += "`nbegin"
$setup_script += "`n if CurStep = ssPostInstall"
$setup_script += "`n then EnvAddPath(ExpandConstant('{app}') + '\server');"
$setup_script += "`nend;"

$setup_script += "`n`nprocedure CurUninstallStepChanged(CurUninstallStep: TUninstallStep);"
$setup_script += "`nbegin"
$setup_script += "`n if CurUninstallStep = usPostUninstall"
$setup_script += "`n then EnvRemovePath(ExpandConstant('{app}' + '\server'));"
$setup_script += "`nend;"

Set-Content -Path "deepstack-windows.iss" -Value $setup_script
2 changes: 2 additions & 0 deletions intelligencelayer/shared/process.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ def __init__(self, model_path: str, reso: int = 640, cuda: bool = False):

def predict(self, img_path: str, confidence: float = 0.4):

confidence = max(0.1,confidence)

img0 = Image.open(img_path).convert("RGB")
img = np.asarray(letterbox(img0, new_shape=self.reso)[0])
img = img[:, :, ::-1].transpose(2, 0, 1)
Expand Down
30 changes: 18 additions & 12 deletions intelligencelayer/shared/scene.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,24 +23,32 @@
import traceback

import torchvision.transforms as transforms
from torchvision.models import resnet50



class SceneModel(object):
def __init__(self, model_path, cuda=False):

self.sess = rt.InferenceSession(model_path)
self.input_name = self.sess.get_inputs()[0].name
self.cuda = cuda

self.model = resnet50(num_classes=365)
checkpoint = torch.load(model_path, map_location=lambda storage, loc: storage)
state_dict = {str.replace(k,'module.',''): v for k,v in checkpoint['state_dict'].items()}
self.model.load_state_dict(state_dict)
self.model.eval()
if self.cuda:
self.model = self.model.cuda()

def predict(self, image_tensors):

out = self.sess.run(None, {self.input_name: image_tensors})
if self.cuda:
image_tensors = image_tensors.cuda()

out = np.array(out)
torch_out = torch.from_numpy(out).squeeze(1)
torch_out = torch.softmax(torch_out, 1)
logit = self.model.forward(image_tensors)
out = torch.softmax(logit, 1)

return out.argmax(), torch_out.max().item()
return out.argmax(), out.max().item()


def scenerecognition(thread_name, delay):
Expand All @@ -56,7 +64,7 @@ def scenerecognition(thread_name, delay):

IMAGE_QUEUE = "scene_queue"
classifier = SceneModel(
os.path.join(SharedOptions.SHARED_APP_DIR, "scene.model"),
os.path.join(SharedOptions.SHARED_APP_DIR, "scene.pt"),
SharedOptions.CUDA_MODE,
)

Expand Down Expand Up @@ -87,10 +95,8 @@ def scenerecognition(thread_name, delay):
),
]
)
img = trans(img)
img = img.numpy()
img = np.expand_dims(img, 0).astype(np.float32)

img = trans(img).unsqueeze(0)

os.remove(img_path)

cl, conf = classifier.predict(img)
Expand Down
2 changes: 1 addition & 1 deletion server/version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2021.01.1
2021.02.1
3 changes: 3 additions & 0 deletions sharedfiles/scene.pt
Git LFS file not shown
6 changes: 5 additions & 1 deletion tests/scene/test_scene.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,16 @@ def test_scene():

image_data = open(os.path.join(DATA_DIR,"scene.jpg"), "rb").read()

assert DEEPSTACK_URL+"/v1/vision/scene" == "http://localhost:80/v1/vision/scene"

response = requests.post(
DEEPSTACK_URL+"/v1/vision/scene",
files={"image": image_data}, data={"api_key": API_KEY}
)

assert response.status_code == 200
response_json = response.json()

assert response.status_code == 200, "Request failed with error: {}".format(response_json["error"])
#assert response.status_code == 200, "Request failed with error: {}".format(response_json["error"])
assert response_json["success"] == True
assert response_json["label"] == "conference_room"
4 changes: 2 additions & 2 deletions tests/tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ $ErrorActionPreference = "Stop"

Write-Host "Testing DeepStack : "$DeepStackURL

$env:TEST_IMAGES_DIR = [IO.Path]::Combine($PSScriptRoot,"test_data")
$env:TEST_DATA_DIR = [IO.Path]::Combine($PSScriptRoot,"test_data")
$env:TEST_DEEPSTACK_URL = $DeepStackURL
$env:TEST_API_KEY = $APIKEY

Expand All @@ -19,5 +19,5 @@ if($IsWindows){
$python = "python"
}

$p = Start-Process -FilePath $python -ArgumentList "-m pytest" -Wait -NoNewWindow
$p = Start-Process -FilePath $python -ArgumentList "-m pytest" -Wait -NoNewWindow
exit($p.ExitCode)
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// <autogenerated />
using System;
using System.Reflection;
[assembly: global::System.Runtime.Versioning.TargetFrameworkAttribute(".NETFramework,Version=v4.5", FrameworkDisplayName = ".NET Framework 4.5")]
Binary file not shown.

0 comments on commit 583c622

Please sign in to comment.