Compare commits
1 Commits
CNNImagePr
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| 56d26795da |
50
Program.cs
50
Program.cs
@@ -63,7 +63,7 @@ namespace CNNImageProcessor
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="sourcePath"></param>
|
/// <param name="sourcePath"></param>
|
||||||
/// <param name="destinationPath"></param>
|
/// <param name="destinationPath"></param>
|
||||||
public static bool ProcessImages(String sourcePath, String destinationPath,int resizeTo,String cnnClientUrl="http://10.0.0.73:5000")
|
public static bool ProcessImages(String sourcePath, String destinationPath,int resizeTo,String cnnClientUrl="http://10.0.0.73:5000",bool useGrayScale=false)
|
||||||
{
|
{
|
||||||
String[] files = Directory.GetFiles(sourcePath,"*.jpg");
|
String[] files = Directory.GetFiles(sourcePath,"*.jpg");
|
||||||
|
|
||||||
@@ -78,7 +78,7 @@ namespace CNNImageProcessor
|
|||||||
Console.WriteLine($"Processing {file}");
|
Console.WriteLine($"Processing {file}");
|
||||||
ImageHelper imageHelper=new ImageHelper();
|
ImageHelper imageHelper=new ImageHelper();
|
||||||
imageHelper.LoadImage(file);
|
imageHelper.LoadImage(file);
|
||||||
// imageHelper.ToGrayScale();
|
if(useGrayScale)imageHelper.ToGrayScale();
|
||||||
imageHelper.Resize(resizeTo,resizeTo);
|
imageHelper.Resize(resizeTo,resizeTo);
|
||||||
Stream stream = imageHelper.ToStream();
|
Stream stream = imageHelper.ToStream();
|
||||||
Stream processed = cnnClient.ProcessImage(stream);
|
Stream processed = cnnClient.ProcessImage(stream);
|
||||||
@@ -314,10 +314,41 @@ namespace CNNImageProcessor
|
|||||||
outStream.Dispose();
|
outStream.Dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//public static (List<Holding> avoid, List<Holding> good) GenerateCodeTestCases(List<Holding> universe)
|
||||||
|
//{
|
||||||
|
// double validationPercent=0.05;
|
||||||
|
// double validationPercentUnseen=0.50;
|
||||||
|
// Console.WriteLine($"Read {universe.Count} holdings");
|
||||||
|
|
||||||
|
// List<Holding> avoid = universe.Where(x=>x.GainLoss<-.05).ToList();
|
||||||
|
// List<Holding> good=universe.Where(x=>x.GainLoss>.05).ToList();
|
||||||
|
|
||||||
|
// int validationCount = (int)(validationPercent * universe.Count);
|
||||||
|
|
||||||
|
// Random rng = new Random();
|
||||||
|
// List<Holding> goodValidation = good.OrderBy(x => rng.Next()).Take(validationCount).ToList();
|
||||||
|
// int goodUnseenCount = (int)(validationPercentUnseen * goodValidation.Count);
|
||||||
|
// List<Holding> goodValidationUnseen = goodValidation.OrderBy(x => rng.Next()).Take(goodUnseenCount).ToList();
|
||||||
|
// good.RemoveAll(x => goodValidationUnseen.Contains(x));
|
||||||
|
// Console.WriteLine($"Validation sample size: {goodValidation.Count}");
|
||||||
|
// Console.WriteLine($"Unseen validation removed from good: {goodValidationUnseen.Count}");
|
||||||
|
// Console.WriteLine($"Remaining good count: {good.Count}");
|
||||||
|
|
||||||
|
|
||||||
|
// List<Holding> avoidValidation = avoid.OrderBy(x => rng.Next()).Take(validationCount).ToList();
|
||||||
|
// int avoidUnseenCount = (int)(validationPercentUnseen * avoidValidation.Count);
|
||||||
|
// List<Holding> avoidValidationUnseen = avoidValidation.OrderBy(x => rng.Next()).Take(avoidUnseenCount).ToList();
|
||||||
|
// avoid.RemoveAll(x => avoidValidationUnseen.Contains(x));
|
||||||
|
// Console.WriteLine($"Validation sample size: {avoidValidation.Count}");
|
||||||
|
// Console.WriteLine($"Unseen validation removed from avoid: {avoidValidationUnseen.Count}");
|
||||||
|
// Console.WriteLine($"Remaining avoid count: {avoid.Count}");
|
||||||
|
|
||||||
|
// return (avoid, good);
|
||||||
|
//}
|
||||||
|
|
||||||
public static (List<Holding> avoid, List<Holding> good) GenerateCodeTestCases(List<Holding> universe)
|
public static (List<Holding> avoid, List<Holding> good) GenerateCodeTestCases(List<Holding> universe)
|
||||||
{
|
{
|
||||||
double validationPercent=0.05;
|
double validationPercent=0.05;
|
||||||
double validationPercentUnseen=0.50;
|
|
||||||
Console.WriteLine($"Read {universe.Count} holdings");
|
Console.WriteLine($"Read {universe.Count} holdings");
|
||||||
|
|
||||||
List<Holding> avoid = universe.Where(x=>x.GainLoss<-.05).ToList();
|
List<Holding> avoid = universe.Where(x=>x.GainLoss<-.05).ToList();
|
||||||
@@ -327,25 +358,18 @@ namespace CNNImageProcessor
|
|||||||
|
|
||||||
Random rng = new Random();
|
Random rng = new Random();
|
||||||
List<Holding> goodValidation = good.OrderBy(x => rng.Next()).Take(validationCount).ToList();
|
List<Holding> goodValidation = good.OrderBy(x => rng.Next()).Take(validationCount).ToList();
|
||||||
int goodUnseenCount = (int)(validationPercentUnseen * goodValidation.Count);
|
|
||||||
List<Holding> goodValidationUnseen = goodValidation.OrderBy(x => rng.Next()).Take(goodUnseenCount).ToList();
|
|
||||||
good.RemoveAll(x => goodValidationUnseen.Contains(x));
|
|
||||||
Console.WriteLine($"Validation sample size: {goodValidation.Count}");
|
Console.WriteLine($"Validation sample size: {goodValidation.Count}");
|
||||||
Console.WriteLine($"Unseen validation removed from good: {goodValidationUnseen.Count}");
|
|
||||||
Console.WriteLine($"Remaining good count: {good.Count}");
|
Console.WriteLine($"Remaining good count: {good.Count}");
|
||||||
|
|
||||||
|
|
||||||
List<Holding> avoidValidation = avoid.OrderBy(x => rng.Next()).Take(validationCount).ToList();
|
List<Holding> avoidValidation = avoid.OrderBy(x => rng.Next()).Take(validationCount).ToList();
|
||||||
int avoidUnseenCount = (int)(validationPercentUnseen * avoidValidation.Count);
|
|
||||||
List<Holding> avoidValidationUnseen = avoidValidation.OrderBy(x => rng.Next()).Take(avoidUnseenCount).ToList();
|
|
||||||
avoid.RemoveAll(x => avoidValidationUnseen.Contains(x));
|
|
||||||
Console.WriteLine($"Validation sample size: {avoidValidation.Count}");
|
Console.WriteLine($"Validation sample size: {avoidValidation.Count}");
|
||||||
Console.WriteLine($"Unseen validation removed from avoid: {avoidValidationUnseen.Count}");
|
|
||||||
Console.WriteLine($"Remaining avoid count: {avoid.Count}");
|
Console.WriteLine($"Remaining avoid count: {avoid.Count}");
|
||||||
|
|
||||||
return (avoid, good);
|
return (avoid, good);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static void GenerateTrainingImages(List<Holding> avoid, List<Holding> good)
|
public static void GenerateTrainingImages(List<Holding> avoid, List<Holding> good)
|
||||||
{
|
{
|
||||||
String cnnClientUrl="http://127.0.0.1:5000";
|
String cnnClientUrl="http://127.0.0.1:5000";
|
||||||
@@ -361,8 +385,8 @@ namespace CNNImageProcessor
|
|||||||
Console.WriteLine($"CNN Server @ {cnnClientUrl} is not responding.");
|
Console.WriteLine($"CNN Server @ {cnnClientUrl} is not responding.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
ProcessImages(@"C:\boneyard\DeepLearning\ModelInputData\0",@"C:\boneyard\DeepLearning\Data\0",imageSize,cnnClientUrl); // Process through PIL and put in C:\boneyard\DeepLearning\Data\0
|
ProcessImages(@"C:\boneyard\DeepLearning\ModelInputData\0",@"C:\boneyard\DeepLearning\Data\0",imageSize,cnnClientUrl,false); // Process through PIL and put in C:\boneyard\DeepLearning\Data\0
|
||||||
ProcessImages(@"C:\boneyard\DeepLearning\ModelInputData\1",@"C:\boneyard\DeepLearning\Data\1",imageSize,cnnClientUrl); // Process through PIL and put in C:\boneyard\DeepLearning\Data\1
|
ProcessImages(@"C:\boneyard\DeepLearning\ModelInputData\1",@"C:\boneyard\DeepLearning\Data\1",imageSize,cnnClientUrl,false); // Process through PIL and put in C:\boneyard\DeepLearning\Data\1
|
||||||
Console.WriteLine("Done.");
|
Console.WriteLine("Done.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user