public InferenceEngineNetwork(InferenceEngineCore core, string xmlFileName, string?weightsFileName = null) { _core = core; var binFileName = weightsFileName ?? Path.ChangeExtension(xmlFileName, ".bin"); ie_core_read_network(core.Core, xmlFileName, binFileName, out _network).Check(nameof(ie_core_read_network)); }
public InferenceEngineNetwork(InferenceEngineCore core, byte[] xmlContent, Blob weights) { _core = core; var span = new Span <byte>(xmlContent); ie_core_read_network_from_memory(core.Core, MemoryMarshal.GetReference(span), span.Length, weights.NativeBlob, out _network).Check(nameof(ie_core_read_network_from_memory)); _weightsBlob = weights; }
public static void Main() { try { //using var bitmap = (System.Drawing.Bitmap)System.Drawing.Image.FromFile(ImageName); using var image = Image.Load <Rgb24>(ImageName); Console.WriteLine($"image: {image}"); if (image.TryGetSinglePixelSpan(out var pixelSpan)) { DumpVersion(); using var core = new InferenceEngineCore(); DumpCoreInformation(core); using var network = new InferenceEngineNetwork(core, NetworkName); DumpNetwork(network); var mainInputName = network.GetInputName(0); var mainOutputName = network.GetOutputName(0); network.SetInputResizeAlgorithm(mainInputName, resize_alg_e.RESIZE_BILINEAR); network.SetInputLayout(mainInputName, layout_e.NCHW); network.SetInputPrecision(mainInputName, precision_e.U8); Console.WriteLine("Create executable network"); using var executableNetwork = new InferenceEngineExecutableNetwork(network, "GPU"); Console.WriteLine("Create request"); using var request = new InferenceEngineRequest(executableNetwork); var imageDimensions = new dimensions_t(1, 3, image.Height, image.Width); var tensorDescription = new tensor_desc_t(layout_e.NHWC, imageDimensions, precision_e.U8); Console.WriteLine("Create blob"); using var inputBlob = new Blob(tensorDescription, MemoryMarshal.Cast <Rgb24, byte>(pixelSpan)); request.SetBlob(mainInputName, inputBlob); for (var i = 0; i < 10; i++) { Console.WriteLine($"Infer {i}"); request.Infer(); Console.WriteLine($"Infer {i} done"); } using var outputBlob = request.GetBlob(mainOutputName); Console.WriteLine($"Output blob. Sizes = {outputBlob.Size} {outputBlob.ByteSize}. [{outputBlob.Layout} {outputBlob.Precision}] {outputBlob.Dimensions}"); } } catch (Exception ex) { Console.Error.WriteLine($"Error: {ex.Message}"); } }
public Detector(InferenceEngineCore core, InferenceEngineNetwork network) { Core = core; _network = network; var mainInputName = network.GetInputName(0); var inputDimensions = network.GetInputDimensions(mainInputName); C = (int)inputDimensions[1]; H = (int)inputDimensions[2]; W = (int)inputDimensions[3]; FrameSize = C * H * W; }
private static void DumpCoreInformation(InferenceEngineCore core) { var devices = core.GetAvailableDevices(); foreach (var device in devices) { Console.WriteLine($"Device: {device}"); var versions = core.GetCoreVersions(device); foreach (var version in versions) { Console.WriteLine($"{version.DeviceName} \"{version.Description}\" {version.Major}.{version.Minor}.{version.BuildNumber}"); } } }
public static async Task <Detector> LoadAsync(string networkName, CancellationToken ct) { var core = new InferenceEngineCore(); try { return(await LoadAsync(core, networkName, ct)); } catch (Exception) { core.Dispose(); throw; } }
public Detector(string networkName) { var core = new InferenceEngineCore(); try { _network = new InferenceEngineNetwork(core, networkName); Core = core; } catch (Exception) { core.Dispose(); throw; } }
public static async Task <InferenceEngineNetwork> LoadAsync(InferenceEngineCore core, string xmlFileName, string?weightsFileName = null, CancellationToken ct = default) { var xmlFile = new FileInfo(xmlFileName); var xmlContents = new byte[xmlFile.Length]; using var ms = new MemoryStream(xmlContents); using (var fs = xmlFile.OpenRead()) { await fs.CopyToAsync(ms, ct).ConfigureAwait(false); } var weightsFile = new FileInfo(weightsFileName ?? Path.ChangeExtension(xmlFileName, ".bin")); var weightsBlob = await Blob.LoadBlobFromFileAsync(weightsFile, ct).ConfigureAwait(false); return(new InferenceEngineNetwork(core, xmlContents, weightsBlob)); }
public Detector(InferenceEngineCore core, string networkName) : this(core, new InferenceEngineNetwork(core, networkName)) { }
public static async Task <Detector> LoadAsync(InferenceEngineCore core, string networkName, CancellationToken ct) { var network = await InferenceEngineNetwork.LoadAsync(core, networkName, ct : ct); return(new Detector(core, network)); }