Skip to content

Commit

Permalink
Form name change and bugfix.
Browse files Browse the repository at this point in the history
  • Loading branch information
AccidentalCitizen committed Jun 22, 2024
1 parent ac95bb7 commit 385b33d
Show file tree
Hide file tree
Showing 8 changed files with 150 additions and 7 deletions.
18 changes: 18 additions & 0 deletions src/AI.TensorFlow/AI.TensorFlow.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="NumSharp" Version="0.30.0" />
<PackageReference Include="OpenCvSharp4" Version="4.9.0.20240103" />
<PackageReference Include="SciSharp.TensorFlow.Redist" Version="2.16.0" />
<PackageReference Include="SciSharp.TensorFlowHub" Version="0.1.5" />
<PackageReference Include="TensorFlow.NET" Version="0.150.0" />
</ItemGroup>

</Project>
104 changes: 104 additions & 0 deletions src/AI.TensorFlow/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
//using System;
//using System.IO;
//using System.Linq;
//using NumSharp;
//using OpenCvSharp;
//using Tensorflow;
//using Tensorflow.Hub;
//using static Tensorflow.Binding;

//class Program
//{
// static void Main(string[] args)
// {
// string modelPath = "ssd_mobilenet_v2";
// string imagePath = "input_image.jpg";
// string outputImagePath = "output_image.jpg";

// // Load the model from TensorFlow Hub
// var model = LoadModelFromHub("https://tfhub.dev/tensorflow/ssd_mobilenet_v2/2");

// // Preprocess the input image
// var inputTensor = PreprocessImage(imagePath);

// // Run the model
// var outputs = model.Call(new Tensor[] { inputTensor });

// // Extract detection results
// var detectionBoxes = outputs[0]["detection_boxes"].numpy();
// var detectionScores = outputs[0]["detection_scores"].numpy();
// var detectionClasses = outputs[0]["detection_classes"].numpy();

// // Highlight detected objects
// HighlightObjects(imagePath, detectionBoxes, detectionScores, detectionClasses, outputImagePath);

// Console.WriteLine($"Output image saved to {outputImagePath}");
// }

// static SavedModel LoadModelFromHub(string url)
// {
// var modulePath = Path.Combine(Path.GetTempPath(), "hub_module");
// if (!Directory.Exists(modulePath))
// {
// Directory.CreateDirectory(modulePath);
// Console.WriteLine($"Downloading model from {url} to {modulePath}");
// // Manually download the model using HttpClient if tfhub.Module.download is unavailable
// using (var client = new System.Net.Http.HttpClient())
// {
// var data = client.GetByteArrayAsync(url).Result;
// File.WriteAllBytes(modulePath, data);
// }
// }
// return SavedModel.Load(modulePath);
// }

// static Tensor PreprocessImage(string imagePath)
// {
// var img = Cv2.ImRead(imagePath);
// Cv2.Resize(img, img, new Size(300, 300));
// img.ConvertTo(img, MatType.CV_32F);
// img = img / 255.0f; // Normalize to [0,1]
// var imgArray = np.array(img.Reshape(new int[] { 1, 300, 300, 3 }));
// return ops.convert_to_tensor(imgArray);
// }

// static void HighlightObjects(string imagePath, NDArray detectionBoxes, NDArray detectionScores, NDArray detectionClasses, string outputImagePath, float threshold = 0.5f)
// {
// var img = Cv2.ImRead(imagePath);
// int height = img.Height;
// int width = img.Width;

// for (int i = 0; i < detectionScores.size; i++)
// {
// float score = detectionScores[i].ToSingle();
// if (score < threshold) continue;

// int classId = detectionClasses[i].ToInt32();
// if (classId != 1 && classId != 43 && classId != 37) continue; // Filter only relevant classes

// float[] box = detectionBoxes[i].ToArray<float>();

// int yMin = (int)(box[0] * height);
// int xMin = (int)(box[1] * width);
// int yMax = (int)(box[2] * height);
// int xMax = (int)(box[3] * width);

// Cv2.Rectangle(img, new Point(xMin, yMin), new Point(xMax, yMax), Scalar.Green, 2);
// string label = GetLabel(classId, score);
// Cv2.PutText(img, label, new Point(xMin, yMin - 10), HersheyFonts.HersheySimplex, 0.5, Scalar.Green, 2);
// }

// Cv2.ImWrite(outputImagePath, img);
// }

// static string GetLabel(int classId, float score)
// {
// return classId switch
// {
// 1 => $"Person: {score:P2}",
// 43 => $"Knife: {score:P2}",
// 37 => $"Gun: {score:P2}",
// _ => $"Unknown: {score:P2}"
// };
// }
//}
11 changes: 10 additions & 1 deletion src/ActuarialIntelligence.sln
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,14 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AI.TTS.EXE", "AI.TTS.EXE\AI
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AI.TTS.Visual", "AI.TTS.Visual\AI.TTS.Visual.csproj", "{26F4EDC1-05BA-41FE-BE71-71DB0E3C5C8D}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BasicTTSAi", "BasicTTSAi\BasicTTSAi.csproj", "{34AD0CD5-C5D9-43B5-8290-C331434A343A}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BasicTTSAi", "BasicTTSAi\BasicTTSAi.csproj", "{34AD0CD5-C5D9-43B5-8290-C331434A343A}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BasicTTS", "BasicTTS\BasicTTS.csproj", "{585E5FD4-CA9B-435E-9A8F-A5F6B2F5E144}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "TensorFlowRedis", "TensorFlowRedis", "{FDF73B9B-D72A-4563-8CAD-DE84FE4EB8CE}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AI.TensorFlow", "AI.TensorFlow\AI.TensorFlow.csproj", "{138BC271-053B-4C53-B6DF-9AEF8753CB85}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -189,6 +193,10 @@ Global
{585E5FD4-CA9B-435E-9A8F-A5F6B2F5E144}.Debug|Any CPU.Build.0 = Debug|Any CPU
{585E5FD4-CA9B-435E-9A8F-A5F6B2F5E144}.Release|Any CPU.ActiveCfg = Release|Any CPU
{585E5FD4-CA9B-435E-9A8F-A5F6B2F5E144}.Release|Any CPU.Build.0 = Release|Any CPU
{138BC271-053B-4C53-B6DF-9AEF8753CB85}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{138BC271-053B-4C53-B6DF-9AEF8753CB85}.Debug|Any CPU.Build.0 = Debug|Any CPU
{138BC271-053B-4C53-B6DF-9AEF8753CB85}.Release|Any CPU.ActiveCfg = Release|Any CPU
{138BC271-053B-4C53-B6DF-9AEF8753CB85}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -218,6 +226,7 @@ Global
{26F4EDC1-05BA-41FE-BE71-71DB0E3C5C8D} = {846214C2-E1CC-4C1E-8F09-86BB5582072B}
{34AD0CD5-C5D9-43B5-8290-C331434A343A} = {846214C2-E1CC-4C1E-8F09-86BB5582072B}
{585E5FD4-CA9B-435E-9A8F-A5F6B2F5E144} = {846214C2-E1CC-4C1E-8F09-86BB5582072B}
{138BC271-053B-4C53-B6DF-9AEF8753CB85} = {FDF73B9B-D72A-4563-8CAD-DE84FE4EB8CE}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {7AFF1FB0-27A8-4765-900D-F53F52605824}
Expand Down
21 changes: 15 additions & 6 deletions src/BasicTTS/BasicTTS.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
</NuGetPackageImportStamp>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<PlatformTarget>x64</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
Expand Down Expand Up @@ -109,21 +109,30 @@
<Reference Include="System.Net.Http" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml" />
<Reference Include="Vlc.DotNet.Core, Version=3.1.0.0, Culture=neutral, PublicKeyToken=84529da31f4eb963, processorArchitecture=MSIL">
<HintPath>..\packages\Vlc.DotNet.Core.3.1.0\lib\net45\Vlc.DotNet.Core.dll</HintPath>
</Reference>
<Reference Include="Vlc.DotNet.Core.Interops, Version=3.1.0.0, Culture=neutral, PublicKeyToken=84529da31f4eb963, processorArchitecture=MSIL">
<HintPath>..\packages\Vlc.DotNet.Core.Interops.3.1.0\lib\net45\Vlc.DotNet.Core.Interops.dll</HintPath>
</Reference>
<Reference Include="Vlc.DotNet.Forms, Version=3.1.0.0, Culture=neutral, PublicKeyToken=84529da31f4eb963, processorArchitecture=MSIL">
<HintPath>..\packages\Vlc.DotNet.Forms.3.1.0\lib\net45\Vlc.DotNet.Forms.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="Form1.cs">
<Compile Include="frmMain.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="Form1.Designer.cs">
<DependentUpon>Form1.cs</DependentUpon>
<Compile Include="frmMain.Designer.cs">
<DependentUpon>frmMain.cs</DependentUpon>
</Compile>
<Compile Include="FormMainHelpers.cs" />
<Compile Include="MLHelper.cs" />
<Compile Include="MoveHelpers.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<EmbeddedResource Include="Form1.resx">
<DependentUpon>Form1.cs</DependentUpon>
<EmbeddedResource Include="frmMain.resx">
<DependentUpon>frmMain.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
3 changes: 3 additions & 0 deletions src/BasicTTS/packages.config
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,7 @@
<package id="System.Runtime.CompilerServices.Unsafe" version="4.5.3" targetFramework="net48" />
<package id="System.Threading.Channels" version="4.7.1" targetFramework="net48" />
<package id="System.Threading.Tasks.Extensions" version="4.5.4" targetFramework="net48" />
<package id="Vlc.DotNet.Core" version="3.1.0" targetFramework="net48" />
<package id="Vlc.DotNet.Core.Interops" version="3.1.0" targetFramework="net48" />
<package id="Vlc.DotNet.Forms" version="3.1.0" targetFramework="net48" />
</packages>

0 comments on commit 385b33d

Please sign in to comment.