Skip to content

Commit

Permalink
fix linux coredump, out of memory
Browse files Browse the repository at this point in the history
  • Loading branch information
gosha20777 committed Aug 17, 2021
1 parent 9e5f676 commit f4bdc86
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 21 deletions.
1 change: 0 additions & 1 deletion App/App.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

<ItemGroup>
<PackageReference Include="CommandLineParser" Version="2.8.0" />
<PackageReference Include="JetBrains.Profiler.SelfApi" Version="2.1.1" />
<PackageReference Include="MetadataExtractor" Version="2.4.3" />
</ItemGroup>

Expand Down
19 changes: 1 addition & 18 deletions App/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -14,16 +13,6 @@ namespace App
static class Program
{
private static List<IObjectDetectionPlugin> _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))
Expand Down Expand Up @@ -108,7 +97,6 @@ static void Infer(InferOptions options)
annotation.SaveToXml(outXmlPath);
}
}
DotMemory.GetSnapshot();
}
static void ShowPlugins(ShowOptions options)
{
Expand Down Expand Up @@ -174,20 +162,15 @@ 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);
_plugins = pm.FindPlugins();
pm = null;

Parser.Default.ParseArguments<InferOptions, ShowOptions>(args)
.WithParsed<InferOptions>(InferUntilExit)
.WithParsed<InferOptions>(Infer)
.WithParsed<ShowOptions>(ShowPlugins);
DotMemory.Detach();
}
}
}
15 changes: 13 additions & 2 deletions LacmusRetinanetPlugin.Cuda/Model.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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;
Expand All @@ -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<IObject> FilterDetections(NDArray[] resultArr, float scale)
Expand Down
5 changes: 5 additions & 0 deletions mk-release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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/
Expand Down

1 comment on commit f4bdc86

@gosha20777
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fix #1 #2

Please sign in to comment.