Code Monkey home page Code Monkey logo

ncnndotnet's Introduction

NcnnDotNet

GitHub Stars GitHub Forks GitHub Issues GitHub Lisence

Package OS x86 x64 ARM ARM64 Nuget
NcnnDotNet (CPU) Windows - - NuGet version
Linux - - NuGet version
OSX - - - NuGet version
NcnnDotNet (GPU) Windows - - - NuGet version
Linux - - - NuGet version
OSX - - - NuGet version
NcnnDotNet (Xamarin) UWP NuGet version
Android NuGet version
iOS - - NuGet version
Package Description Nuget
NcnnDotNet.Extensions.Drawing GDI+ Extensions NuGet version

Demo

YoloV3 on Xamarin.Android, iOS and UWP

Related Projects

Dependencies Libraries and Products

License: The BSD 3-Clause License

Author: THL A29. Limited, a Tencent company

Principal Use: A high-performance neural network inference framework optimized for the mobile platform in C++. Main goal of NcnnDotNet is what wraps ncnn by C#.

License: The BSD 3-Clause License

Author: Intel Corporation, Willow Garage, Itseez

Principal Use: Uses to read and show image data.

ncnndotnet's People

Contributors

takuya-takeuchi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ncnndotnet's Issues

Mat from Bitmap or byte[]

It's possible to have a way to get a Mat from a Bitmap or a byte[]?

Right now I need to create a Bitmap, use ToMap Extension from OpenCVSharp then I could use Mat.FromPixels.

Would be much simple if I could get the Mat use in NcnnDotNet directly.

How should I use NcnnDotNet.C.Ncnn.MatToPixels() method?

Hi,
I want to save images after inference, which is a NcnnDotNet.Mat object after inference. I noticed that there is a NcnnDotNet.C.Ncnn.MatToPixels() method that could be the equivalent of the to_pixels() method in the ncnn. However, I got an error "Unable to convert NcnnDotNet.Mat to NcnnDotNet.C.Mat".
Is there any way that I can convert NcnnDotNet.Mat to NcnnDotNet.C.Mat, or should I save the image with another approach?
PS: I tried to save the byte data copied from NcnnDotNet.Mat.Data, but I can only get a meaningless picture.
Much appreciated.

ParamDict.Set?

Hello,

sorry for the (perhaps dumb) question, but Im new to ncnn. Im trying to port RealSR to c# and came to the following lines:

    ncnn::ParamDict pd;
    pd.set(0, 3);// bicubic
    pd.set(1, 4.f);
    pd.set(2, 4.f);
    bicubic_4x->load_param(pd);

...but the ParamDict-class does not have any method / constructor to "fill" the dict...

Do I get something wrong here? Can anyone help me with thsi?

Thanks a lot

Carl

Extractor error when using with camera

Hi @takuya-takeuchi ,

I got problem with running NcnnDotNet with camera.

2023-12-26_21h14_53

I do not know if the Extractor should be created one time at application starting or re-create in every frame of camera?

Can you please have a look on this problem?

Thank you very much,

mat from stream or byte array

so excited to find NcnnDotNet , It's great work!
is it possible to transfer byte array or stream to mat ?
In .net core website, I want to infer the file (IFormFile) uploaed without saving it.
how to make it ?
thx!

Change version format

ncnn uses YYYYMMDD as tag name and releases.
But, this format may be changed.
If version format is changed to X.Y.Z format, new version is treated as old.

So format should be 0.0.0.YYYYMMDD.

what wrong of the code? scoreBlob, bboxBlob,landmarkBlob are all zero!

public static void Retina(NcnnDotNet.OpenCV.Mat src)
{
    // Model from https://github.com/nihui/ncnn-assets/tree/master/models
    Net net = new Net();
    net.Opt.UseVulkanCompute = false;
    net.LoadParam(@"Models\mnet.25-opt.param");
    net.LoadModel(@"Models\mnet.25-opt.bin");

    var imgW = src.Cols;
    var imgH = src.Rows;
    NcnnDotNet.Mat @in = NcnnDotNet.Mat.FromPixelsResize(
        pixel: src.Data,
        type: PixelType.Bgr2Rgb,
        width: src.Cols,
        height: src.Rows,
        targetWidth: imgW,
        targetHeight: imgH
    );

    NcnnDotNet.Extractor ex = net.CreateExtractor();

    ex.Input("data", @in);

    var scoreBlob = new NcnnDotNet.Mat();
    var bboxBlob = new NcnnDotNet.Mat();
    var landmarkBlob = new NcnnDotNet.Mat();
    ex.Extract("face_rpn_cls_prob_reshape_stride32", scoreBlob);
    ex.Extract("face_rpn_bbox_pred_stride32", bboxBlob);
    ex.Extract("face_rpn_landmark_pred_stride32", landmarkBlob);
}

Passing pointer to OpenCVDotNet.OpenCV Mat

Hi;

First of all, thank you for your effort developing this great library.

Currently I am working for face detection using UltraFaceDotNet and EmguCV. However I have problem in passing pointer to NcnnDotNet.OpenCV Mat. Below is my code:

                UltraFace _ultraFace = UltraFace.Create(_param);
...
                using Emgu.CV.Mat frame = new Emgu.CV.Mat();
                _videoCapture.Retrieve(frame, 0);
                using var inMat = NcnnDotNet.Mat.FromPixels(frame.Ptr, NcnnDotNet.PixelType.Bgr2Rgb, frame.Cols, frame.Rows);
                var faceInfos = _ultraFace.Detect(inMat).ToArray();
                RectangleF[] rectangles = new RectangleF[faceInfos.Length];
                for (var j = 0; j < faceInfos.Length; j++)
                {
                    var face = faceInfos[j];
                    var pt1 = new Point<float>(face.X1, face.Y1);
                    var pt2 = new Point<float>(face.X2, face.Y2);
                    float width = face.X2 - face.X1;
                    float height = face.Y2 - face.Y1;
                    rectangles[j] = new RectangleF(face.X1, face.Y1, width, height);
                    //Cv2.Rectangle(frame, pt1, pt2, new Scalar<double>(0, 255, 0), 2);
                }

When I run the code, I got error
System.Exception: 'Capture error'
Inner Exception
AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt

Is there any way to solve the problem?
Or if Ncnndotnet.OpenCV Mat can received bitmap, then I can pass bitmap parameter from Emgu CV Mat.

Thank you

how to implentment custom layer

Hi,
I'm trying porting example of yolov5
but there's a costom layer named YoloV5Focus
how to handle this case in c#
would you like to give some instructions on this?
thanks!

Speed in GPU is slower than Cpu

Hi @takuya-takeuchi
I test Yolov3 sample with two versions of NcnnDotnet (only cpu).

With version 0.0.0.20230101 is more than 500 miliseconds
With version 0.0.0.20221224 is only 78 miliseconds

Both test on Windows 11 x64, Cpu version of NcnnDotNet, the same image size is 1000x754

Is there any changes in Api that can cause lower speed?

Thanks

Implements layers (0.0.0.20200106)

  • absval.h(AbsVal)
  • argmax.h(ArgMax)
  • batchnorm.h(BatchNorm)
  • bias.h(Bias)
  • binaryop.h(BinaryOp)
  • bnll.h(BNLL)
  • cast.h(Cast)
  • clip.h(Clip)
  • concat.h(Concat)
  • convolution.h(Convolution)
  • convolutiondepthwise.h(ConvolutionDepthWise)
  • crop.h(Crop)
  • deconvolution.h(Deconvolution)
  • deconvolutiondepthwise.h(DeconvolutionDepthWise)
  • dequantize.h(Dequantize)
  • detectionoutput.h(DetectionOutput)
  • dropout.h(Dropout)
  • eltwise.h(Eltwise)
  • elu.h(ELU)
  • embed.h(Embed)
  • exp.h(Exp)
  • expanddims.h(ExpandDims)
  • flatten.h(Flatten)
  • hardsigmoid.h(HardSigmoid)
  • hardswish.h(HardSwish)
  • innerproduct.h(InnerProduct)
  • input.h(Input)
  • instancenorm.h(InstanceNorm)
  • interp.h(Interp)
  • log.h(Log)
  • lrn.h(LRN)
  • lstm.h(LSTM)
  • memorydata.h(MemoryData)
  • mvn.h(MVN)
  • noop.h(Noop)
  • normalize.h(Normalize)
  • packing.h(Packing)
  • padding.h(Padding)
  • permute.h(Permute)
  • pooling.h(Pooling)
  • power.h(Power)
  • prelu.h(PReLU)
  • priorbox.h(PriorBox)
  • proposal.h(Proposal)
  • psroipooling.h(PSROIPooling)
  • quantize.h(Quantize)
  • reduction.h(Reduction)
  • relu.h(ReLU)
  • reorg.h(Reorg)
  • requantize.h(Requantize)
  • reshape.h(Reshape)
  • rnn.h(RNN)
  • roialign.h(ROIAlign)
  • roipooling.h(ROIPooling)
  • scale.h(Scale)
  • selu.h(SELU)
  • shufflechannel.h(ShuffleChannel)
  • sigmoid.h(Sigmoid)
  • slice.h(Slice)
  • softmax.h(Softmax)
  • split.h(Split)
  • spp.h(SPP)
  • squeeze.h(Squeeze)
  • tanh.h(TanH)
  • threshold.h(Threshold)
  • tile.h(Tile)
  • unaryop.h(UnaryOp)
  • yolodetectionoutput.h(YoloDetectionOutput)
  • yolov3detectionoutput.h(Yolov3DetectionOutput

Set option?

hello,
i'm trying to port a ncnn project
i need to set some option like these

	net.opt.use_winograd_convolution = false;
	net.opt.use_sgemm_convolution = false;

i see that they are referenced in this repo but i can not access them

this may be a dumb question but is there a way to do that? thanks

Cannot build NcnnDotNet.Native

When I run "pwsh BuildWindows.ps1", it said "Error: This platform is not support". Could you please upload NcnnDotNetNative.dll?

Fixed platorm x64

Output directory always be likeexamples/YoloV3/bin/x64/Debug/netcoreapp3.1.
It is occured by nuget/nuspec/build/NcnnDotNet.props
So we have to remove it from nuspec file?

At least, it occurs the following error on linux arm device.

$ dotnet run -c Release -r linux-arm64
/usr/share/dotnet/sdk/3.1.410/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.RuntimeIdentifierInference.targets(166,5): error NETSDK1032: The RuntimeIdentifier platform 'linux-arm64' and the PlatformTarget 'x64' must be compatible. [/home/t-takeuchi/Work/OpenSource/NcnnDotNet/examples/YoloV3/YoloV3.csproj]

Memory overhead against original ncnn

Hello again
I was able to write a c# port of stable-diffusion-ncnn using your library and it works as intended.
However i noticed a big difference in terms of RAM usage

For example, the following code uses 5.5 GB of RAM

Net net = new Net();
net.LoadParam("./assets/UNetModel-fp16.param");
net.LoadModel("./assets/UNetModel-fp16.bin");

while the original one in c++ uses only 3GB

net.load_param("assets/UNetModel-fp16.param");
net.load_model("assets/UNetModel-fp16.bin");

Its not vital for me to reduce memory usage but out of curiosity, do you have any idea of what is causing this?
Thanks for your time

How to convert Mat to Bitmap ?

Hi @takuya-takeuchi

Thank you so much for the great library

I want to display Mat image on Winforms C# GUI. Could you help me create a function to convert Mat to Bitmap c#?

I gave some tries but i could not.

Thank you in advance

(System.AccessViolationException) Bitmap ToMat Issues

Hello, I've tried just about everything I can think of and have tried so many different methods and combinations. I am unsure of what I am doing wrong here.. The only thing I can think of is the PixelFormat but I am unsure if that really matters when converted that way I am doing it.

First I grab a screenshot:

public Bitmap? ScreenGrab(Rectangle detectionBox)
{
    if (_graphics == null || _screenCaptureBitmap == null || _screenCaptureBitmap.Width != detectionBox.Width || _screenCaptureBitmap.Height != detectionBox.Height)
    {
        _screenCaptureBitmap?.Dispose();
        _screenCaptureBitmap = new Bitmap(detectionBox.Width, detectionBox.Height);

        _graphics?.Dispose();
        _graphics = Graphics.FromImage(_screenCaptureBitmap);
    }

    _graphics.CopyFromScreen(detectionBox.Left, detectionBox.Top, 0, 0, detectionBox.Size);

    return _screenCaptureBitmap;
}

I have tried to convert the bitmap so many different ways and all of them have lead to a System.AccessViolationException.
This was my last attempt using OpenCVSharp's Extensions:

Bitmap? frame = ScreenGrab(detectionBox);
if (frame == null) return null;

//float[] inputArray = BitmapToFloatArray(frame);
//if (inputArray == null) return null;

OpenCvSharp.Mat mat = OpenCvSharp.Extensions.BitmapConverter.ToMat(frame);

using var NCmat = new NcnnDotNet.Mat(mat.Width, mat.Height, mat.Data);
_ex.Input("in0", NCmat);

using var outMat = new NcnnDotNet.Mat();
_ex.Extract("out0", outMat);

Debug.WriteLine(outMat.W);

The violation is on the Input bool on this line:

if (NativeMethods.net_Extractor_input(base.NativePtr, bytes, bytes.Length, @in.NativePtr) != 0)

image

Here are the model files:
yolov8n_ncnn_model.zip

Could not return label greater than 10

Hello @takuya-takeuchi
I'm running NcnnDorNet on windows 10 X64 and I have a customized model with 25 classes.
when I use NcnnDotNet ,Everything is going well and the bounding boxes are returned successfully expect the labels with id greater than 10. their label are returned 10.
However it doesn't happen for the labels with lower than 10.

Specify C++ version for build

On OSX, compiler says

/Users/t-takeuchi/Work/OpenSource/NcnnDotNet/src/NcnnDotNet.Native/ncnn/layer/layer.h:17:11: warning: 'auto' type specifier is a C++11 extension [-Wc++11-extensions]

NcnnDotNet with OpencvSharp

Hi @takuya-takeuchi
I use VideoCapture from OpencvSharp4 to capture video like this:
OpenCvSharp.VideoCapture mCap = new OpenCvSharp.VideoCapture(0); OpenCvSharp.Mat mat = mCap.RetrieveMat();

I convert OpenCvSharp.Mat to NcnnDotNet.Ma like this:
NcnnDotNet.Mat mm = NcnnDotNet.Mat.FromPixels(mat.Data, NcnnDotNet.PixelType.Bgr2Rgb, mat.Cols, mat.Rows);

Then i convert back to Bitmap for testing result
System.Drawing.Bitmap bm2 = mm.ToBitmap(PixelType.Rgb, PixelFormat.Format24bppRgb);
bm2.Save("C:\bitmap.jpg");

Bit it gives me wrong bitmap

bitmap

Can you please have a look on my code and point me what i was wrong?
Thank you very much

how to use? no doc.

how to use? no doc.

i'm try use this lib for yolov7.
but show is error. how to use ?

doc???

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.