Skip to content

Commit 8c20e58

Browse files
author
Chris Maunder
committed
Updated to 2.6.5
1 parent 0f00f42 commit 8c20e58

File tree

63 files changed

+541
-313
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+541
-313
lines changed

.gitignore

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -371,10 +371,10 @@ src/modules/ObjectDetectionYoloRKNN/custom-models
371371
/src/modules/TrainingObjectDetectionYOLOv5/train
372372
/src/modules/TrainingObjectDetectionYOLOv5/zoo
373373

374-
/demos/modules/DotNetLongProcess/assets/
375-
/demos/modules/DotNetSimple/assets/
376-
/demos/modules/PythonLongProcess/assets
377-
/demos/modules/PythonSimple/assets
374+
src/demos/modules/DotNetLongProcess/assets/
375+
src/demos/modules/DotNetSimple/assets/
376+
src/demos/modules/PythonLongProcess/assets
377+
src/demos/modules/PythonSimple/assets
378378

379379
# Config files -----------------------------------------------------------------
380380

src/SDK/NET/Analysis/ModuleWorkerBase.cs

Lines changed: 82 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,10 @@ public abstract class ModuleWorkerBase : BackgroundService
7474
public string? InferenceDevice { get; set; } = "CPU";
7575

7676
/// <summary>
77-
/// Gets or sets the name of the hardware acceleration execution provider
77+
/// Gets or sets the name of the hardware acceleration execution provider (meaning the
78+
/// library being used to power the GPU, such as DirectML, Torch, TF etc)
7879
/// </summary>
79-
public string? InferenceLibrary { get; set; } = "CPU";
80+
public string? InferenceLibrary { get; set; } = string.Empty;
8081

8182
/// <summary>
8283
/// Gets the logger instance.
@@ -262,89 +263,36 @@ private async Task ProcessQueue(CancellationToken token, int taskNumber)
262263
if (request is null)
263264
continue;
264265

266+
string? command = request.payload?.command?.ToLower();
267+
if (command == null)
268+
continue;
269+
265270
// Special shutdown request
266271
string? requestModuleId = request.payload?.GetValue("moduleId");
267-
if (request.payload?.command?.EqualsIgnoreCase("quit") == true &&
268-
requestModuleId?.EqualsIgnoreCase(_moduleId) == true)
272+
if (command == "quit" && requestModuleId?.EqualsIgnoreCase(_moduleId) == true)
269273
{
270274
await ShutDown(0);
271275
return;
272276
}
273277

274-
ExpandoObject response;
275-
276278
Stopwatch stopWatch = Stopwatch.StartNew();
277-
if (request.payload?.command?.EqualsIgnoreCase("get_module_status") == true)
278-
{
279-
response = GetModuleStatus(request);
280-
}
281-
else if (request.payload?.command?.EqualsIgnoreCase("get_command_status") == true)
282-
{
283-
response = await GetCommandStatus(request).ConfigureAwait(false);
284-
}
285-
else if (request.payload?.command?.EqualsIgnoreCase("cancel_command") == true)
286-
{
287-
response = CancelRequest(request).ToExpando();
288-
}
289-
else
279+
280+
ExpandoObject response = command switch
290281
{
291-
ModuleResponse moduleResponse = Process(request);
292-
if (!_doNotLogCommands.Contains(request.reqtype))
293-
UpdateStatistics(moduleResponse);
294-
295-
if (moduleResponse.LongProcessMethod is not null)
296-
{
297-
if (_longRunningTask is not null && !_longRunningTask.IsCompleted)
298-
{
299-
response = new {
300-
Success = false,
301-
CommandId = _longRunningCommandId,
302-
Error = "A long running command is already in progress"
303-
}.ToExpando();
304-
}
305-
else
306-
{
307-
// We have a previous long running process that is now done, but we
308-
// have not stored (nor returned) the result. We can read the result
309-
// now, but we have to start a new process, so...???
310-
// if (_longRunningTask is not null && _longRunningTask.IsCompleted &&
311-
// _lastLongRunningLastOutput is null)
312-
// _lastLongRunningLastOutput = ...
313-
314-
// Store request Id as the command Id for later, reset the last result
315-
string? commandId = request.reqid;
316-
317-
_longRunningCommandId = commandId;
318-
_lastLongRunningOutput = null;
319-
_longRunningTask = null;
320-
321-
// Start the long running process
322-
Console.WriteLine("Starting long process with command ID " + commandId);
323-
324-
_longProcessCancellationTokenSource = new CancellationTokenSource();
325-
CancellationToken cancellationToken = _longProcessCancellationTokenSource.Token;
326-
_longRunningTask = Task.Run(() => moduleResponse.LongProcessMethod(request, cancellationToken),
327-
cancellationToken);
328-
329-
response = new {
330-
Success = true,
331-
CommandId = commandId,
332-
Message = "Command is running in the background",
333-
CommandStatus = "running"
334-
}.ToExpando();
335-
}
336-
}
337-
else
338-
response = moduleResponse.ToExpando();
339-
}
282+
"get_module_status" => GetModuleStatus(request),
283+
"get_command_status" => await GetCommandStatus(request).ConfigureAwait(false),
284+
"cancel_command" => CancelRequest(request).ToExpando(),
285+
_ => ProcessModuleCommands(request)
286+
};
287+
340288
stopWatch.Stop();
341289

342290
// Fill in system-added values for the response
343291
response = response.Merge(new {
344292
ModuleName = ModuleName,
345293
ModuleId = _moduleId,
346294
ProcessMs = stopWatch.ElapsedMilliseconds,
347-
Command = request.payload?.command ?? string.Empty,
295+
Command = command ?? string.Empty,
348296
RequestId = request.reqid
349297
}.ToExpando());
350298

@@ -379,6 +327,71 @@ private async Task ProcessQueue(CancellationToken token, int taskNumber)
379327
_cancellationTokenSource.Cancel();
380328
}
381329

330+
/// <summary>
331+
/// Processes a command sent to a module.
332+
/// </summary>
333+
/// <param name="request">The incoming request</param>
334+
/// <returns>An expando object with the results</returns>
335+
private ExpandoObject ProcessModuleCommands(BackendRequest request)
336+
{
337+
ExpandoObject response;
338+
339+
ModuleResponse moduleResponse = Process(request);
340+
341+
if (!_doNotLogCommands.Contains(request.reqtype))
342+
UpdateStatistics(moduleResponse);
343+
344+
if (moduleResponse.LongProcessMethod is not null)
345+
{
346+
if (_longRunningTask is not null && !_longRunningTask.IsCompleted)
347+
{
348+
response = new
349+
{
350+
Success = false,
351+
CommandId = _longRunningCommandId,
352+
Error = "A long running command is already in progress"
353+
}.ToExpando();
354+
}
355+
else
356+
{
357+
// We have a previous long running process that is now done, but we
358+
// have not stored (nor returned) the result. We can read the result
359+
// now, but we have to start a new process, so...???
360+
// if (_longRunningTask is not null && _longRunningTask.IsCompleted &&
361+
// _lastLongRunningLastOutput is null)
362+
// _lastLongRunningLastOutput = ...
363+
364+
// Store request Id as the command Id for later, reset the last result
365+
string? commandId = request.reqid;
366+
367+
_longRunningCommandId = commandId;
368+
_lastLongRunningOutput = null;
369+
_longRunningTask = null;
370+
371+
// Start the long running process
372+
Console.WriteLine("Starting long process with command ID " + commandId);
373+
374+
_longProcessCancellationTokenSource = new CancellationTokenSource();
375+
CancellationToken cancellationToken = _longProcessCancellationTokenSource.Token;
376+
_longRunningTask = moduleResponse.LongProcessMethod(request, cancellationToken);
377+
378+
response = new
379+
{
380+
Success = true,
381+
CommandId = commandId,
382+
Message = "Command is running in the background",
383+
CommandStatus = "running"
384+
}.ToExpando();
385+
}
386+
}
387+
else
388+
{
389+
response = moduleResponse.ToExpando();
390+
}
391+
392+
return response;
393+
}
394+
382395
/// <summary>
383396
/// This stops the application
384397
/// </summary>

src/SDK/NET/Common/ModuleDescription.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -181,9 +181,9 @@ public static void Initialise(this ModuleDescription module, string currentServe
181181
module.CheckVersionAgainstModuleReleases();
182182
SetLatestCompatibleVersion(module, currentServerVersion);
183183

184-
// REVIEW: [Chris] The module.IsCompatible() method is not used here because it doesn't check the
185-
// LatestCompatibleRelease property. However, it there is a LatestCompatibleRelease, then the module
186-
// is compatible.
184+
// The module.IsCompatible() method is not used here because it doesn't check the
185+
// LatestCompatibleRelease property. However, it there is a LatestCompatibleRelease,
186+
// then the module is compatible.
187187

188188
module.Status = module.LatestCompatibleRelease is not null
189189
? ModuleStatusType.Available : ModuleStatusType.NotAvailable;

src/SDK/Python/Python.pyproj

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,12 @@
1414
<Name>CodeProject.AI SDK</Name>
1515
<IsWindowsApplication>False</IsWindowsApplication>
1616
<EnableNativeCodeDebugging>False</EnableNativeCodeDebugging>
17-
<SuppressPackageInstallationPrompt>True</SuppressPackageInstallationPrompt>
18-
<SuppressEnvironmentCreationPrompt>True</SuppressEnvironmentCreationPrompt>
1917
</PropertyGroup>
20-
<PropertyGroup Condition="'$(Configuration)' == 'Release'" />
18+
2119
<PropertyGroup>
2220
<VisualStudioVersion Condition=" '$(VisualStudioVersion)' == '' ">10.0</VisualStudioVersion>
2321
</PropertyGroup>
22+
2423
<ItemGroup>
2524
<Compile Include="common.py" />
2625
<Compile Include="module_logging.py" />
@@ -33,14 +32,16 @@
3332
<Compile Include="utils\image_utils.py" />
3433
<Compile Include="utils\environment_check.py" />
3534
</ItemGroup>
35+
3636
<ItemGroup>
37-
<Content Include="pyproject.toml" />
3837
<Content Include="requirements.txt" />
3938
</ItemGroup>
39+
4040
<ItemGroup>
4141
<Folder Include="analysis\" />
4242
<Folder Include="training\" />
4343
<Folder Include="utils\" />
4444
</ItemGroup>
45+
4546
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\Python Tools\Microsoft.PythonTools.targets" />
4647
</Project>

src/SDK/Scripts/utils.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1456,7 +1456,7 @@ function installPythonPackagesByName () {
14561456
fi
14571457

14581458
# echo "[DEBUG] '${venvPythonCmdPath}' -m pip install ${pipFlags} '${package_name}' --target '${packagesDirPath}' ${pip_options}"
1459-
if [ "${os}" = "linux" ]; then
1459+
if [ "${os}" = "linux" ] || [ "${os}" = "macos" ]; then
14601460
if [ "${verbosity}" = "loud" ]; then
14611461
eval "$venvPythonCmdPath" -m pip install "${package_name}" --target "${packagesDirPath}" ${pip_options} ${pipFlags}
14621462
else
@@ -1754,7 +1754,7 @@ function installRequiredPythonPackages () {
17541754
# If the module specifier isn't a URL or .whl then extract the package's name
17551755
module_name=""
17561756
if [ "${package_name:0:4}" != "http" ] && [ "${package_name:(-4)}" != ".whl" ]; then
1757-
module_name=$(echo "$package_name" | sed 's/[<=>].*//g')
1757+
module_name=$(echo "$package_name" | sed 's/[<=>,~].*//g')
17581758
# Now remove any string from [ onwards to get 'module' from module[variant]
17591759
module_name=${module_name%%[*}
17601760
fi
@@ -1774,7 +1774,7 @@ function installRequiredPythonPackages () {
17741774
if [ "${verbosity}" != "quiet" ]; then write "Installing ${package_name}..." $color_info; fi
17751775

17761776
# echo "[DEBUG] '${venvPythonCmdPath}' -m pip install '${package_name}' --target '${packagesDirPath}' ${currentOption} ${pipFlags}"
1777-
if [ "${os}" = "linux" ]; then
1777+
if [ "${os}" = "linux" ] || [ "${os}" = "macos" ]; then
17781778
# No, I don't know why eval is needed in Linux but not elsewhere
17791779
if [ "${verbosity}" = "loud" ]; then
17801780
eval "${venvPythonCmdPath}" -m pip install "${package_name}" --target "${packagesDirPath}" ${currentOption} ${pipFlags}

src/SDK/install.bat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ if /i "!useJq!" == "false" (
4444
dotnet build "!sdkPath!\Utilities\ParseJSON" /property:GenerateFullPaths=true /consoleloggerparameters:NoSummary -c Release >NUL
4545
if exist "!sdkPath!\Utilities\ParseJSON\bin\Release\net7.0\" (
4646
pushd "!sdkPath!\Utilities\ParseJSON\bin\Release\net7.0\"
47-
move * ..\..\..\ > /dev/null
47+
move * ..\..\..\ >NUL
4848
popd
4949
)
5050
)

src/demos/modules/DotNetLongProcess/install.bat

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
::
33
:: .NET Long Process Demo
44
::
5-
:: This script is only called from ..\..\setup.bat
5+
:: This script is only called from ..\..\..\setup.bat
66
::
77
:: For help with install scripts, notes on variables and methods available, tips,
88
:: and explanations, see /src/modules/install_script_help.md
99

1010
@if "%1" NEQ "install" (
11-
echo This script is only called from ..\..\setup.bat
11+
echo This script is only called from ..\..\..\setup.bat
1212
@pause
1313
@goto:eof
1414
)

src/demos/modules/DotNetLongProcess/install.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@
66
#
77
# This script is called from the ObjectDetectionYOLOv5Net directory using:
88
#
9-
# bash ../../setup.sh
9+
# bash ../../../setup.sh
1010
#
1111
# The setup.sh script will find this install.sh file and execute it.
1212
#
1313
# For help with install scripts, notes on variables and methods available, tips,
1414
# and explanations, see /src/modules/install_script_help.md
1515

1616
if [ "$1" != "install" ]; then
17-
read -t 3 -p "This script is only called from: bash ../../setup.sh"
17+
read -t 3 -p "This script is only called from: bash ../../../setup.sh"
1818
echo
1919
exit 1
2020
fi

src/demos/modules/DotNetLongProcess/modulesettings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
"PublishingInfo" : {
99
"Description": "Provides a template for a .NET module that runs a long process.",
10-
"Category": "Computer Vision",
10+
"Category": "Demo Module",
1111
"Stack": "C#",
1212
"License": "MIT",
1313
"LicenseUrl": "https://opensource.org/licenses/MIT",

src/demos/modules/DotNetSimple/install.bat

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
::
33
:: .NET YOLO Object Detection
44
::
5-
:: This script is only called from ..\..\setup.bat
5+
:: This script is only called from ..\..\..\setup.bat
66
::
77
:: For help with install scripts, notes on variables and methods available, tips,
88
:: and explanations, see /src/modules/install_script_help.md
99

1010
@if "%1" NEQ "install" (
11-
echo This script is only called from ..\..\setup.bat
11+
echo This script is only called from ..\..\..\setup.bat
1212
@pause
1313
@goto:eof
1414
)

0 commit comments

Comments
 (0)