Buenas !
Este es un post especial, ya que es el 1ro que escribo completamente desde mi . Estoy seguro que Javier (@jsuarezruiz), Yeray (@JosueYeray), Braulio (@braulio_sl), Luis, Sara, Roberto y otros mac users estarían orgullosos de mi 😀
Basado en el post anterior, he compilado y ejecutado mi proyecto Custom Vision Marvel en Docker para Mac. La experiencia es buenísima, y bash también es una novedad interesante!
docker build -t elbruno/cvmarvel:3.0 .
El siguiente paso es obtener en ID y ejecutar la misma.
El paso final es utilizar CURL para hacer una petición HTTP Post con una imagen para analizar. Es muy simple, salvo que me tomo unos minutos y unas búsquedas en bing el darme cuenta que hay utilizar el prefijo @ en la llamada desde la consola! Iron Fist detected !
curl -X POST http://127.0.0.1:8080/image -F imageData=@img1.jpg
Ok, el entorno de pruebas con Docker esta funcionando, así que ahora es momento de utilizar Visual Studio for Mac. En realidad la app es una .Net Core Console App, que podría crear en Visual Studio Code, pero esta es la excusa perfecta para comenzar a conocer Visual Studio for Mac.
Mi codigo de pruebas esta en Azure DevOps, así que después de sincronizar los repositorios, ya pude crear un nuevo proyecto a mi solución.
Un par de lineas de código C# en la console app y ya pude realizar el análisis de la imagen utilizando el contenedor con el proyecto de Custom Vision
El código es muy simple:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.IO; | |
using System.Net.Http; | |
using System.Net.Http.Headers; | |
using System.Threading.Tasks; | |
using Newtonsoft.Json; | |
using Newtonsoft.Json.Linq; | |
namespace CustomVisionMarvelConsoleDocker01 | |
{ | |
static class Program | |
{ | |
static void Main() | |
{ | |
MakePredictionRequest("IMG01.jpg").Wait(); | |
Console.ReadLine(); | |
} | |
static async Task MakePredictionRequest(string imageFilePath) | |
{ | |
var client = new HttpClient(); | |
var url = "http://127.0.0.1:8080/image"; | |
var byteData = GetImageAsByteArray(imageFilePath); | |
using (var content = new ByteArrayContent(byteData)) | |
{ | |
content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream"); | |
var response = await client.PostAsync(url, content); | |
var jsonResponse = await response.Content.ReadAsStringAsync(); | |
var prettyJson = JToken.Parse(jsonResponse).ToString(Formatting.Indented); | |
Console.WriteLine(prettyJson); | |
} | |
} | |
static byte[] GetImageAsByteArray(string imageFilePath) | |
{ | |
var fileStream = new FileStream(imageFilePath, FileMode.Open, FileAccess.Read); | |
var binaryReader = new BinaryReader(fileStream); | |
return binaryReader.ReadBytes((int)fileStream.Length); | |
} | |
} | |
} |
Happy coding!
Saludos @ Toronto
El Bruno
References
My Posts
- Object recognition with Custom Vision and ONNX in Windows applications using WinML (1)
- Object recognition with Custom Vision and ONNX in Windows applications using WinML (2)
- Object recognition with Custom Vision and ONNX in Windows applications using Windows ML, drawing frames (3)
- Object recognition with Custom Vision and ONNX in Windows applications using Windows ML, calculate FPS (4)
- Can’t install Docker on Windows 10 Home, need Pro or Enterprise (5)
- Running a Custom Vision project in a local Docker Container (6)
Windows 10 and YOLOV2 for Object Detection Series
- Introduction to YoloV2 for object detection
- Create a basic Windows10 App and use YoloV2 in the camera for object detection
- Transform YoloV2 output analysis to C# classes and display them in frames
- Resize YoloV2 output to support multiple formats and process and display frames per second
- How to convert Tiny-YoloV3 model in CoreML format to ONNX and use it in a Windows 10 App
- Updated demo using Tiny YOLO V2 1.2, Windows 10 and YOLOV2 for Object Detection Series
- Alternatives to Yolo for object detection in ONNX format