Разработка автоматизированной системы классификации товаров по изображениям
Дипломная работа - Компьютеры, программирование
Другие дипломы по предмету Компьютеры, программирование
ter++)
{parameter = new ParameterForDelegate (preparedList, counter);thread = new Thread (new ParameterizedThreadStart (ParallelCreate));. Start (parameter);. Join (10);
}
}ParameterForDelegate
{List [] preparedList, int counter)
{. preparedList = preparedList;. counter = counter;
}
}ParallelCreate (object parameter)
{ [] preparedList = ( (ParameterForDelegate) parameter). preparedList;counter = ( (ParameterForDelegate) parameter). counter;(int j = 0; j < preparedList [counter]. Count; j++)
{net = new NeuralNetwork (smallNetworkLayers);. Create (preparedList [counter] [j]. FullName);. TryParse (preparedList [counter] [j]. Name. Replace (". ann", ""), out net. id);. Add (net);. Sleep (10);(NetworkCreatedEvent! = null)();
}
}
#endregion Паралельная инициализация сетей/*Dictionary*/void Work (object image)
{imageToDetect = (Bitmap) image; ();(! smallNetworksInitialized)();. WriteLine ("Работа нейронных сетей");(var network in smallNetworks)
{watch = Stopwatch. StartNew ();. Add (network, network. Work (imageToDetect));. Stop ();. WriteLine ( ( (double) watch. ElapsedTicks / (double) Stopwatch. Frequency). ToString ());
}= result;. Sleep (50);
// return result;();
}int GetTrainDataCreationWorkAmount ()
{[] trainDirectoryInfo = (new DirectoryInfo (initialDirectory + @"\64x48")). GetDirectories ();
// return trainDirectoryInfo. Length * 2;trainDirectoryInfo. Length;
}int GetParallelTrainDataCreationWorkAmount ()
{[] trainDirectoryInfo = (new DirectoryInfo (initialDirectory + @"\64x48")). GetDirectories ();trainDirectoryInfo. Length;
}void CreateSmallTrainData ()
{();[] trainDirectoryInfo = (new DirectoryInfo (initialDirectory + @"\64x48")). GetDirectories (); // Чтение каталога всех категорий= trainDirectoryInfo. Length;(int i = 0; i < trainDirectoryInfo. Length; i++)
{[] items = trainDirectoryInfo [i]. GetDirectories (); // список товаров в категории (); // изображения товаров в других категориях(var item in items)
{. AddRange (item. GetFiles ("*. jpg"));
}(int j = 0; j < trainDirectoryInfo. Length; j++)
{(j == i);[] falseItems = trainDirectoryInfo [j]. GetDirectories ();(var item in falseItems)
{. AddRange (item. GetFiles ("*. jpg"));
}
}trainImagesCount = (uint) (images. Count + falseImages. Count);net = new NeuralNetwork (smallNetworkLayers);. id = Convert. ToInt32 (trainDirectoryInfo [i]. Name);. CreateTrainDataFile (trainDirectoryInfo [i]. FullName, images, true);
// net. CreateTrainDataFile (trainDirectoryInfo [i]. FullName, images, true, trainImagesCount);
// net. CreateTrainDataFile (trainDirectoryInfo [i]. FullName, falseImages, false, trainImagesCount);
}
}void CreateSmallTrainData (List wholeTDI)
{(int i = 0; i < trainDirectoryInfo. Count; i++)
{[] items = trainDirectoryInfo [i]. GetDirectories (); ();(var item in items)
{. AddRange (item. GetFiles ("*. jpg"));
}(int j = 0; j < wholeTDI. Count; j++)
{(wholeTDI [j] == trainDirectoryInfo [i]);[] falseItems = wholeTDI [j]. GetDirectories ();(var item in falseItems)
{. AddRange (item. GetFiles ("*. jpg"));
}
}trainImagesCount = (uint) (images. Count + falseImages. Count);net = new NeuralNetwork (smallNetworkLayers);. id = Convert. ToInt32 (trainDirectoryInfo [i]. Name);
// net. CreateTrainDataFile (trainDirectoryInfo [i]. FullName, images, true);. CreateTrainDataFile (trainDirectoryInfo [i]. FullName, images, true, trainImagesCount);. CreateTrainDataFile (trainDirectoryInfo [i]. FullName, falseImages, false, trainImagesCount);
}
}void CreateSmallTrainData (List trainDirectoryInfo)
{(int i = 0; i < trainDirectoryInfo. Count; i++)
{[] items = trainDirectoryInfo [i]. GetDirectories (); ();(var item in items)
{. AddRange (item. GetFiles ("*. jpg"));
}net = new NeuralNetwork (smallNetworkLayers);. id = Convert. ToInt32 (trainDirectoryInfo [i]. Name);watch = Stopwatch. StartNew ();. CreateTrainDataFile (trainDirectoryInfo [i]. FullName, images, true);. Stop ();. WriteLine ( ( (double) watch. ElapsedTicks / (double) Stopwatch. Frequency / (double) images. Count). ToString ());
}
}void ParallelCreateSmallTrainData ()
{();[] trainDirectoryInfo = (new DirectoryInfo (initialDirectory + @"\64x48")). GetDirectories (); // Чтение каталога всех категорий= trainDirectoryInfo. Length;preparedList = ThreadHelper. SplitList (trainDirectoryInfo. ToList categories in preparedList)
{thread = new Thread (()
{. WriteLine ("Создание файлов обучения");(categories);
}
);. Start ();. Join (10);
}
}int GetNetworkTrainWorkAmount ()
{[] trainDirectoryInfo = (new DirectoryInfo (initialDirectory + @"\64x48")). GetDirectories (); // Чтение каталога всех категорийcounter = 0;(var category in trainDirectoryInfo)
{trainFilePath = category. FullName + " // " + category. Name +". tr";(File. Exists (trainFilePath))
{++;
}
}counter;
}void TrainSmallNetworks ()
{();= GetNetworkTrainWorkAmount ();[] trainDirectoryInfo = (new DirectoryInfo (initialDirectory + @"\64x48")). GetDirectories (); // Чтение каталога всех категорий(var category in trainDirectoryInfo)
{trainFilePath = category. FullName + "\\" + category. Name +". tr";(File. Exists (trainFilePath))
{net = new NeuralNetwork (smallNetworkLayers);. id = Convert. ToInt32 (category. Name);watch = Stopwatch. StartNew ();. Train (trainFilePath);. Stop ();. WriteLine ("Training " + ( (double) watch. ElapsedTicks / (double) Stopwatch. Frequency). ToString ());anotherWatch = Stopwatch. StartNew ();. Save (initialDirectory + @"\64x48\");. Stop ();. WriteLine ("Saving " + ( (double) anotherWatch. ElapsedTicks / (double) Stopwatch. Frequency). ToString ());();
}
}
}void TrainSmallNetworks (List trainDirectoryInfo)
{(var category in trainDirectoryInfo)
{trainFilePath = category. FullName + " // " + category. Name +". tr";(File. Exists (trainFilePath))
{net = new NeuralNetwork (smallNetworkLayers);. id = Convert. ToInt32 (category. Name);
// Stopwatch watch = Stopwatch. StartNew ();. Train (trainFilePath);
// watch. Stop ();
// Debug. WriteLine ( ( (double) watch. ElapsedTicks / (double) Stopwatch. Frequency). ToString ());. Save (initialDirectory + @"\64x48\");();
}
}
}void ParallelTrainSmallNetworks ()
{();[] trainDirectoryInfo = (new DirectoryInfo (initialDirectory + @"\64x48")). GetDirectories (); // Чтение каталога всех категорий= GetNetworkTrainWorkAmount ();preparedList = ThreadHelper. SplitList (trainDirectoryInfo. ToList categories in preparedList)
{thread = new Thread (()
{. WriteLine ("Обучение сетей");(categories);
}
);. SetApartmentState (ApartmentState. STA);. Start ();. Join (50);
}
}void CascadeTrainSmallNetworks ()
{[] trainDirectoryInfo = (new DirectoryInfo (initialDirectory + @"\64x48")). GetDirectories (); // Чтение каталога всех категорий(var category in trainDirectoryInfo)
{trainFilePath = category. FullName + " // " + category. Name +". tr";net = new NeuralNetwork (smallNetworkLayers);. id = Convert. ToInt32 (category. Name);. CascadeTrain (trainFilePath);. Save (initialDirectory + @"\64x48\");
}
}void WipeTrainData ()
{[] trainDirectoryInfo = (new DirectoryInfo (initialDirectory + @"\64x48")). GetDirectories ();(var dir in trainDirectoryInfo)
{tr = dir. GetFiles ("*. tr");
{[0]. Delete ();
}(Exception)
{;
}
}
}void WipeNetworks ()
{ann = (new DirectoryInfo (initialDirectory + @"\64x48")). GetFiles ("*. ann");(var n in ann)
{
{. Delete ();
}(Exception)
{;
}
}
}void Wipe ()
{();();
}
}
}