Enhancements.
This commit is contained in:
@@ -11,7 +11,7 @@ namespace MarketData.CNNProcessing
|
||||
{
|
||||
public class CNNClient
|
||||
{
|
||||
public enum Model{resnet50,inception,vgg16,lenet5,ping};
|
||||
public enum Model{resnet50,resnet50B,inception,vgg16,lenet5,ping};
|
||||
private static readonly string Alive="Alive";
|
||||
private readonly HttpClient client = new HttpClient();
|
||||
private string baseUrl;
|
||||
@@ -42,6 +42,15 @@ namespace MarketData.CNNProcessing
|
||||
}
|
||||
}
|
||||
|
||||
// This method is used to process an image through PIL. All images that are being used in training should ultimately be processed through
|
||||
// PIL (Python Image Library) so that images can be normalized by python prior to training. We do this because we use PIL during the
|
||||
// prediction process and we want all images used in training/validation and all images used for prediction to be touched by and processed
|
||||
// by PIL
|
||||
public Stream ProcessImage(Stream stream)
|
||||
{
|
||||
return UploadImage(baseUrl+"/process_image", stream);
|
||||
}
|
||||
|
||||
public bool Ping()
|
||||
{
|
||||
try
|
||||
@@ -56,6 +65,7 @@ namespace MarketData.CNNProcessing
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private async Task<String> Upload(String url,Stream stream)
|
||||
{
|
||||
try
|
||||
@@ -78,6 +88,31 @@ namespace MarketData.CNNProcessing
|
||||
return null;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// This method uploads an image stream to the specified url and receives the processed image back.
|
||||
/// The processed image simply processes the image through PIL (Python Image Library)
|
||||
/// </summary>
|
||||
private Stream UploadImage(String url,Stream stream)
|
||||
{
|
||||
try
|
||||
{
|
||||
using (HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, url))
|
||||
{
|
||||
int streamEnd = Convert.ToInt32(stream.Length);
|
||||
byte[] byteArray = new byte[streamEnd];
|
||||
stream.Read(byteArray, 0, streamEnd);
|
||||
request.Content=new ByteArrayContent(byteArray);
|
||||
HttpResponseMessage response = client.SendAsync(request).GetAwaiter().GetResult();
|
||||
return response.Content.ReadAsStreamAsync().GetAwaiter().GetResult();
|
||||
}
|
||||
}
|
||||
catch(Exception exception)
|
||||
{
|
||||
MDTrace.WriteLine(LogLevel.DEBUG,String.Format("Exception encountered: {0}",exception.ToString()));
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private async Task<String> Upload(String url)
|
||||
{
|
||||
try
|
||||
|
||||
Reference in New Issue
Block a user