From f4bdc86e6632681da4d1ea0e3992fc849021a048 Mon Sep 17 00:00:00 2001 From: gosha20777 Date: Tue, 17 Aug 2021 23:08:31 +0300 Subject: [PATCH] fix linux coredump, out of memory --- App/App.csproj | 1 - App/Program.cs | 19 +------------------ LacmusRetinanetPlugin.Cuda/Model.cs | 15 +++++++++++++-- mk-release.sh | 5 +++++ 4 files changed, 19 insertions(+), 21 deletions(-) diff --git a/App/App.csproj b/App/App.csproj index ebe8ed4..c167b8d 100755 --- a/App/App.csproj +++ b/App/App.csproj @@ -2,7 +2,6 @@ - diff --git a/App/Program.cs b/App/Program.cs index 58cecff..69f3263 100755 --- a/App/Program.cs +++ b/App/Program.cs @@ -4,7 +4,6 @@ using System.IO; using System.Linq; using CommandLine; -using JetBrains.Profiler.SelfApi; using LacmusPlugin; using MetadataExtractor; using Directory = System.IO.Directory; @@ -14,16 +13,6 @@ namespace App static class Program { private static List _plugins; - - static void InferUntilExit(InferOptions options) - { - var command = ""; - while (command?.ToLower() != "q") - { - Infer(options); - command = Console.ReadLine(); - } - } static void Infer(InferOptions options) { if (!Directory.Exists(options.InputDir)) @@ -108,7 +97,6 @@ static void Infer(InferOptions options) annotation.SaveToXml(outXmlPath); } } - DotMemory.GetSnapshot(); } static void ShowPlugins(ShowOptions options) { @@ -174,10 +162,6 @@ static void Main(string[] args) { var options = new InferOptions(); var showOptions = new ShowOptions(); - DotMemory.EnsurePrerequisite(); - var config = new DotMemory.Config(); - config.SaveToDir("/home/gosha20777/Documents/projects/lacmus-plugins/mem-profiling"); - DotMemory.Attach(config); var pluginsDir = Path.Join(AppDomain.CurrentDomain.BaseDirectory, "plugins"); var pm = new PluginManager(pluginsDir); @@ -185,9 +169,8 @@ static void Main(string[] args) pm = null; Parser.Default.ParseArguments(args) - .WithParsed(InferUntilExit) + .WithParsed(Infer) .WithParsed(ShowPlugins); - DotMemory.Detach(); } } } \ No newline at end of file diff --git a/LacmusRetinanetPlugin.Cuda/Model.cs b/LacmusRetinanetPlugin.Cuda/Model.cs index 610f7fd..11b07da 100755 --- a/LacmusRetinanetPlugin.Cuda/Model.cs +++ b/LacmusRetinanetPlugin.Cuda/Model.cs @@ -35,7 +35,17 @@ public Model(float threshold) _graph = LoadModelGraph(_pbFile); _preprocessingGraph = BuildPreprocessingGraph(); - _session = tf.Session(_graph); + //_session = tf.Session(_graph); + //_session = tf.Session(); + _session = tf.Session(_graph, + new ConfigProto + { + GpuOptions = new GPUOptions + { + AllowGrowth = true, + PerProcessGpuMemoryFraction = 0.6 + } + }); _preprocessingSession = tf.Session(_preprocessingGraph); _inputModelTensor = _graph.OperationByName("input_1"); @@ -120,7 +130,7 @@ private Graph BuildPreprocessingGraph() var resizeJpeg = tf.image.resize_bilinear(dimsExpander, size, half_pixel_centers: true, name: "output"); return resizeJpeg.graph; } - private float ComputeImageScale(int width, int height, int minSide = 2100, int maxSide = 2100) + private float ComputeImageScale(int width, int height, int minSide = 1500, int maxSide = 2000) { var smallestSide = Math.Min(width, height); var scale = minSide / (float)smallestSide; @@ -129,6 +139,7 @@ private float ComputeImageScale(int width, int height, int minSide = 2100, int m { scale = maxSide / (float)largestSide; } + Console.WriteLine(scale); return scale; } private IEnumerable FilterDetections(NDArray[] resultArr, float scale) diff --git a/mk-release.sh b/mk-release.sh index 3d91b24..2e10c06 100755 --- a/mk-release.sh +++ b/mk-release.sh @@ -3,6 +3,8 @@ rm -rf ./build && \ rm -rf ./App/bin/Release/ \ rm -rf ./LacmusPlugin/bin/Release/ \ rm -rf ./LacmusRetinanetPlugin/bin/Release/ +rm -rf ./LacmusRetinanetPlugin.Cuda/bin/Release/ +rm -rf ./LacmusRetinanetPlugin.DirectML/bin/Release/ echo "restoring packeges\n" dotnet restore echo -n "building for linux\n" @@ -17,6 +19,9 @@ echo -n "building lacmus plugin [cuda]\n" dotnet publish --framework net5.0 -c Release -o ./build/plugins/LacmusRetinanetPlugin.Cuda LacmusRetinanetPlugin.Cuda/LacmusRetinanetPlugin.Cuda.csproj echo -n "building lacmus plugin [direct-ml]\n" dotnet publish --framework net5.0 -c Release -o ./build/plugins/LacmusRetinanetPlugin.DirectML LacmusRetinanetPlugin.DirectML/LacmusRetinanetPlugin.DirectML.csproj + +mkdir ./build/app/linux_amd64/plugins +cp -r ./build/plugins/LacmusRetinanetPlugin.Cuda ./build/app/linux_amd64/plugins/LacmusRetinanetPlugin.Cuda #cd ./bin/app/ #zip -r -9 ./linux.zip ./linux/ #zip -r -9 ./win10.zip ./win10/