private void classfiyGPUBtn_Click(object sender, EventArgs e) { if (!Msnhnet.WithGPU()) { MessageBox.Show("Msnhnet not build with GPU"); return; } if (!netInited) { MessageBox.Show("Network is not inited"); return; } if (pictureBox1.Image == null) { MessageBox.Show("there is no pic in picBox!"); return; } try { Rectangle rect = new Rectangle(0, 0, pictureBox1.Image.Width, pictureBox1.Image.Height); // image的长宽,非pictureBox的长宽 Bitmap bitmap = (Bitmap)pictureBox1.Image; //image转bitmap BitmapData bmpdata = bitmap.LockBits(rect, ImageLockMode.ReadWrite, bitmap.PixelFormat); int best = net.RunClassifyList(bmpdata, MsnhnetDef.PredDataType.PRE_DATA_FC32_C3, false, true); bitmap.UnlockBits(bmpdata); string[] labelList = labels.Split('\n'); float time = net.GetGpuForwardTime(); richTextBox1.AppendText("GPU inference time:" + time.ToString() + " ms\n"); richTextBox1.AppendText("GPU inferece result: " + labelList[best] + "\n"); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void yoloGPUBtn_Click(object sender, EventArgs e) { if (!netInited) { MessageBox.Show("Network is not inited"); return; } if (!Msnhnet.WithGPU()) { MessageBox.Show("Msnhnet not build with GPU"); return; } try { Rectangle rect = new Rectangle(0, 0, pictureBox1.Image.Width, pictureBox1.Image.Height); // image的长宽,非pictureBox的长宽 Bitmap bitmap = (Bitmap)pictureBox1.Image; //image转bitmap BitmapData bmpdata = bitmap.LockBits(rect, ImageLockMode.ReadWrite, bitmap.PixelFormat); List <Msnhnet.BBox> bboxes = net.RunYoloList(bmpdata, false, true); bitmap.UnlockBits(bmpdata); for (int i = 0; i < bboxes.Count; i++) { bboxes[i] = ImgPro.bboxResize2Org(bboxes[i], net.GetInputDim().width, net.GetInputDim().height, bitmap.Width, bitmap.Height); } pictureBox1.Image = drawYolo(bitmap, bboxes, labels); float time = net.GetGpuForwardTime(); richTextBox1.AppendText("GPU inference time:" + time.ToString() + " ms\n"); } catch (Exception ex) { MessageBox.Show(ex.Message); } }