Skip to content

Commit

Permalink
add missing asm tools in CI, run it every night (AlexeyAB#7790)
Browse files Browse the repository at this point in the history
* add missing asm tools

* run CI every night

* add csharp tool
  • Loading branch information
cenit authored Jun 11, 2021
1 parent 83e3779 commit 7ff80b1
Show file tree
Hide file tree
Showing 6 changed files with 188 additions and 3 deletions.
33 changes: 32 additions & 1 deletion .github/workflows/ccpp.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
name: Darknet Continuous Integration

on: [push, workflow_dispatch]
on:
push:
workflow_dispatch:
schedule:
- cron: '0 0 * * *'

env:
VCPKG_BINARY_SOURCES: 'clear;nuget,vcpkgbinarycache,readwrite'
Expand Down Expand Up @@ -68,6 +72,11 @@ jobs:

- uses: lukka/get-cmake@latest

- name: Update apt
run: sudo apt update
- name: Install dependencies
run: sudo apt install yasm nasm

- name: 'Install CUDA'
run: ./scripts/deploy-cuda.sh

Expand Down Expand Up @@ -123,6 +132,11 @@ jobs:

- uses: lukka/get-cmake@latest

- name: Update apt
run: sudo apt update
- name: Install dependencies
run: sudo apt install yasm nasm

- name: 'Install CUDA'
run: ./scripts/deploy-cuda.sh

Expand Down Expand Up @@ -161,6 +175,11 @@ jobs:

- uses: lukka/get-cmake@latest

- name: Update apt
run: sudo apt update
- name: Install dependencies
run: sudo apt install yasm nasm

- name: 'Install CUDA'
run: ./scripts/deploy-cuda.sh

Expand Down Expand Up @@ -513,6 +532,18 @@ jobs:
run: ./build.ps1 -ForceCPP -DisableInteractive -DoNotUpdateDARKNET


win-csharp:
runs-on: windows-latest
steps:
- uses: actions/checkout@v2

- uses: lukka/get-cmake@latest

- name: 'Build'
shell: pwsh
run: ./build.ps1 -EnableCSharpWrapper -DisableInteractive -DoNotUpdateDARKNET


win-intlibs-cuda:
runs-on: windows-latest
steps:
Expand Down
27 changes: 27 additions & 0 deletions .github/workflows/on_pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ jobs:

- uses: lukka/get-cmake@latest

- name: Update apt
run: sudo apt update
- name: Install dependencies
run: sudo apt install yasm nasm

- name: 'Install CUDA'
run: ./scripts/deploy-cuda.sh

Expand Down Expand Up @@ -120,6 +125,11 @@ jobs:

- uses: lukka/get-cmake@latest

- name: Update apt
run: sudo apt update
- name: Install dependencies
run: sudo apt install yasm nasm

- name: 'Install CUDA'
run: ./scripts/deploy-cuda.sh

Expand Down Expand Up @@ -155,6 +165,11 @@ jobs:

- uses: lukka/get-cmake@latest

- name: Update apt
run: sudo apt update
- name: Install dependencies
run: sudo apt install yasm nasm

- name: 'Install CUDA'
run: ./scripts/deploy-cuda.sh

Expand Down Expand Up @@ -492,6 +507,18 @@ jobs:
run: ./build.ps1 -ForceCPP -DisableInteractive -DoNotUpdateDARKNET


win-csharp:
runs-on: windows-latest
steps:
- uses: actions/checkout@v2

- uses: lukka/get-cmake@latest

- name: 'Build'
shell: pwsh
run: ./build.ps1 -EnableCSharpWrapper -DisableInteractive -DoNotUpdateDARKNET


win-intlibs-cuda:
runs-on: windows-latest
steps:
Expand Down
5 changes: 5 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ option(ENABLE_CUDNN "Enable CUDNN" ON)
option(ENABLE_CUDNN_HALF "Enable CUDNN Half precision" ON)
option(ENABLE_ZED_CAMERA "Enable ZED Camera support" ON)
option(ENABLE_VCPKG_INTEGRATION "Enable VCPKG integration" ON)
option(ENABLE_CSHARP_WRAPPER "Enable building a csharp wrapper" OFF)
option(VCPKG_BUILD_OPENCV_WITH_CUDA "Build OpenCV with CUDA extension integration" ON)
option(VCPKG_USE_OPENCV2 "Use legacy OpenCV 2" OFF)
option(VCPKG_USE_OPENCV3 "Use legacy OpenCV 3" OFF)
Expand Down Expand Up @@ -576,3 +577,7 @@ install(FILES
"${PROJECT_BINARY_DIR}/DarknetConfigVersion.cmake"
DESTINATION "${INSTALL_CMAKE_DIR}"
)

if(ENABLE_CSHARP_WRAPPER)
add_subdirectory(src/csharp)
endif()
18 changes: 16 additions & 2 deletions build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,14 @@ param (
[switch]$ForceStaticLib = $false,
[switch]$ForceVCPKGCacheRemoval = $false,
[switch]$ForceSetupVS = $false,
[switch]$EnableCSharpWrapper = $false,
[Int32]$ForceGCCVersion = 0,
[Int32]$ForceOpenCVVersion = 0,
[Int32]$NumberOfBuildWorkers = 8,
[string]$AdditionalBuildSetup = "" # "-DCMAKE_CUDA_ARCHITECTURES=30"
)

$build_ps1_version = "0.9.4"
$build_ps1_version = "0.9.5"

$ErrorActionPreference = "SilentlyContinue"
Stop-Transcript | out-null
Expand Down Expand Up @@ -242,6 +243,15 @@ else {
Write-Host "VisualStudio integration is enabled, please pass -DoNotSetupVS to the script to disable"
}

if ($EnableCSharpWrapper -and ($IsWindowsPowerShell -or $IsWindows)) {
Write-Host "Yolo C# wrapper integration is enabled. Will be built with Visual Studio generator. Disabling Ninja"
$DoNotUseNinja = $true
}
else {
$EnableCSharpWrapper = $false
Write-Host "Yolo C# wrapper integration is disabled, please pass -EnableCSharpWrapper to the script to enable. You must be on Windows!"
}

if ($DoNotUseNinja) {
Write-Host "Ninja is disabled"
}
Expand Down Expand Up @@ -410,7 +420,7 @@ elseif ((Test-Path "${env:WORKSPACE}/vcpkg") -and $UseVCPKG) {
$AdditionalBuildSetup = $AdditionalBuildSetup + " -DENABLE_VCPKG_INTEGRATION:BOOL=ON"
}
elseif (-not($null -eq ${RUNVCPKG_VCPKG_ROOT_OUT})) {
if((Test-Path "${RUNVCPKG_VCPKG_ROOT_OUT}") -and $UseVCPKG) {
if ((Test-Path "${RUNVCPKG_VCPKG_ROOT_OUT}") -and $UseVCPKG) {
$vcpkg_path = "${RUNVCPKG_VCPKG_ROOT_OUT}"
$env:VCPKG_ROOT = "${RUNVCPKG_VCPKG_ROOT_OUT}"
$vcpkg_root_set_by_this_script = $true
Expand Down Expand Up @@ -592,6 +602,10 @@ if (-Not $EnableOPENCV_CUDA) {
$AdditionalBuildSetup = $AdditionalBuildSetup + " -DVCPKG_BUILD_OPENCV_WITH_CUDA:BOOL=OFF"
}

if ($EnableCSharpWrapper) {
$additional_build_setup = $additional_build_setup + " -DENABLE_CSHARP_WRAPPER:BOOL=ON"
}

$build_folder = "./build_release"
if (-Not $DoNotDeleteBuildFolder) {
Write-Host "Removing folder $build_folder" -ForegroundColor Yellow
Expand Down
19 changes: 19 additions & 0 deletions src/csharp/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@

project(YoloWrapper LANGUAGES CSharp)
include(CSharpUtilities)

add_library(${PROJECT_NAME}
${PROJECT_NAME}.cs
)

target_link_libraries(${PROJECT_NAME} PRIVATE dark)

set_property(TARGET ${PROJECT_NAME} PROPERTY VS_DOTNET_REFERENCES
"System"
"System.Runtime.InteropServices"
)

install(TARGETS ${PROJECT_NAME}
RUNTIME DESTINATION "${INSTALL_BIN_DIR}"
COMPONENT dev
)
89 changes: 89 additions & 0 deletions src/csharp/YoloWrapper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
using System;
using System.Runtime.InteropServices;

namespace Darknet
{
public class YoloWrapper : IDisposable
{
private const string YoloLibraryName = "yolo_cpp_dll.dll";
private const int MaxObjects = 1000;

[DllImport(YoloLibraryName, EntryPoint = "init")]
private static extern int InitializeYolo(string configurationFilename, string weightsFilename, int gpu);

[DllImport(YoloLibraryName, EntryPoint = "detect_image")]
private static extern int DetectImage(string filename, ref BboxContainer container);

[DllImport(YoloLibraryName, EntryPoint = "detect_mat")]
private static extern int DetectImage(IntPtr pArray, int nSize, ref BboxContainer container);

[DllImport(YoloLibraryName, EntryPoint = "dispose")]
private static extern int DisposeYolo();

[StructLayout(LayoutKind.Sequential)]
public struct bbox_t
{
public UInt32 x, y, w, h; // (x,y) - top-left corner, (w, h) - width & height of bounded box
public float prob; // confidence - probability that the object was found correctly
public UInt32 obj_id; // class of object - from range [0, classes-1]
public UInt32 track_id; // tracking id for video (0 - untracked, 1 - inf - tracked object)
public UInt32 frames_counter;
public float x_3d, y_3d, z_3d; // 3-D coordinates, if there is used 3D-stereo camera
};

[StructLayout(LayoutKind.Sequential)]
public struct BboxContainer
{
[MarshalAs(UnmanagedType.ByValArray, SizeConst = MaxObjects)]
public bbox_t[] candidates;
}

public YoloWrapper(string configurationFilename, string weightsFilename, int gpu)
{
InitializeYolo(configurationFilename, weightsFilename, gpu);
}

public void Dispose()
{
DisposeYolo();
}

public bbox_t[] Detect(string filename)
{
var container = new BboxContainer();
var count = DetectImage(filename, ref container);

return container.candidates;
}

public bbox_t[] Detect(byte[] imageData)
{
var container = new BboxContainer();

var size = Marshal.SizeOf(imageData[0]) * imageData.Length;
var pnt = Marshal.AllocHGlobal(size);

try
{
// Copy the array to unmanaged memory.
Marshal.Copy(imageData, 0, pnt, imageData.Length);
var count = DetectImage(pnt, imageData.Length, ref container);
if (count == -1)
{
throw new NotSupportedException($"{YoloLibraryName} has no OpenCV support");
}
}
catch (Exception exception)
{
return null;
}
finally
{
// Free the unmanaged memory.
Marshal.FreeHGlobal(pnt);
}

return container.candidates;
}
}
}

0 comments on commit 7ff80b1

Please sign in to comment.