Code cleanup
This commit is contained in:
50
Program.cs
50
Program.cs
@@ -63,7 +63,7 @@ namespace CNNImageProcessor
|
||||
/// </summary>
|
||||
/// <param name="sourcePath"></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");
|
||||
|
||||
@@ -78,7 +78,7 @@ namespace CNNImageProcessor
|
||||
Console.WriteLine($"Processing {file}");
|
||||
ImageHelper imageHelper=new ImageHelper();
|
||||
imageHelper.LoadImage(file);
|
||||
// imageHelper.ToGrayScale();
|
||||
if(useGrayScale)imageHelper.ToGrayScale();
|
||||
imageHelper.Resize(resizeTo,resizeTo);
|
||||
Stream stream = imageHelper.ToStream();
|
||||
Stream processed = cnnClient.ProcessImage(stream);
|
||||
@@ -314,10 +314,41 @@ namespace CNNImageProcessor
|
||||
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)
|
||||
{
|
||||
double validationPercent=0.05;
|
||||
double validationPercentUnseen=0.50;
|
||||
Console.WriteLine($"Read {universe.Count} holdings");
|
||||
|
||||
List<Holding> avoid = universe.Where(x=>x.GainLoss<-.05).ToList();
|
||||
@@ -327,25 +358,18 @@ namespace CNNImageProcessor
|
||||
|
||||
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 void GenerateTrainingImages(List<Holding> avoid, List<Holding> good)
|
||||
{
|
||||
String cnnClientUrl="http://127.0.0.1:5000";
|
||||
@@ -361,8 +385,8 @@ namespace CNNImageProcessor
|
||||
Console.WriteLine($"CNN Server @ {cnnClientUrl} is not responding.");
|
||||
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\1",@"C:\boneyard\DeepLearning\Data\1",imageSize,cnnClientUrl); // Process through PIL and put in C:\boneyard\DeepLearning\Data\1
|
||||
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,false); // Process through PIL and put in C:\boneyard\DeepLearning\Data\1
|
||||
Console.WriteLine("Done.");
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user