Разработка автоматизированной системы классификации товаров по их изображениям

Дипломная работа - Компьютеры, программирование

Другие дипломы по предмету Компьютеры, программирование



ase | RegexOptions.Compiled);smallPicturesRegex = new Regex(@"(

{

//Stopwatch watch = Stopwatch.StartNew();

imgList=newList(); ;matchId = itemIdRegex.Match(item.OuterHtml);(matchId.Success)

{= Convert.ToInt64(matchId.Groups[1].Value);

}matchsmallPictures = smallPicturesRegex.Match(item.OuterHtml);(matchsmallPictures.Success)

{.AddImage(itemId, matchsmallPictures.Groups[1].Value, false);= matchsmallPictures.NextMatch();

}matchbigPictures = bigPicturesRegex.Match(item.OuterHtml);(matchbigPictures.Success)

{.AddImage(itemId, matchbigPictures.Groups[1].Value, true);= matchbigPictures.NextMatch();

}

/********************************************/

//watch.Stop();

//Debug.WriteLine(((double)watch.ElapsedTicks / (double)Stopwatch.Frequency).ToString());

}

}void AddImage(Int64 itemId, string thumbnailURL, bool isBig)

{img = new Image(itemId, id, thumbnailURL, isBig);.Add(img);

}void SaveImages(string initialDirectory)

{(var image in categoryImages)

{watch = Stopwatch.StartNew();.Save(initialDirectory);.Stop();.WriteLine(((double)watch.ElapsedTicks / (double)Stopwatch.Frequency).ToString());

}();

}

}

}

Модуль NetworkController

using System;System.Collections.Generic;System.Linq;System.Text;System.IO;System.Drawing;System.Threading;System.Diagnostics;grabberMolotok.DBEngine;grabberMolotok.Threading;FANNCategoriesDetector

{NetworkController

{dbEngine; //движок бд workResult; //результат работы сетейsmallNetworksInitialized; //флаг инициализации малых сетейbool SmallNetworksInitialized

{{ return smallNetworksInitialized; }

}bigNetworksInitialized; //флаг инициализации больших сетейbool BigNetworksInitialized

{{ return bigNetworksInitialized; }{ bigNetworksInitialized = value; }

}initialDirectory; //рабочая директорияstring InitialDirectory

{{ return initialDirectory; }

}[] smallNetworkLayers = { 3072, 512, 1 }; //слои малых сетей[] bigNetworkLayers = { 12000, 1000, 1 }; //слои больших сетей

int trainDataCreationCounter; //счетчик создания данных для обученияtrainDataCreationWorkAmount; //объём работы данных обученияtrainDataCreationThreadCount; //количество потоков данных обучения

public int TrainDataCreationThreadCount

{{ return trainDataCreationThreadCount; }{ trainDataCreationThreadCount = value; }

}networkTrainCounter; //счетчик обучения сетейnetworkTrainWorkAmount; //объём работы обучения сетей

int networkTrainThreadCount; //количество потоков обучения сетей

public int NetworkTrainThreadCount

{{ return networkTrainThreadCount; }{ networkTrainThreadCount = value; }

}networkCreateCounter; //счетчик создания сетейnetworkCreateWorkAmount; //объём создания сетейnetworkCreateThreadCount; //потоки создания сетейint NetworkCreateThreadCount

{{ return networkCreateThreadCount; }{ networkCreateThreadCount = value; }

}

#region Событияdelegate void AllTrainDataCreationCompletedEventHandler();static event AllTrainDataCreationCompletedEventHandler AllTrainDataCreationCompletedEvent;delegate void AllNetworkTrainedEventHandler();static event AllNetworkTrainedEventHandler AllNetworkTrainedEvent;delegate void AllNetworkCreatedEventHandler();static event AllNetworkCreatedEventHandler AllNetworkCreatedEvent;delegate void AllNetworkWorkedEventHandler();static event AllNetworkWorkedEventHandler AllNetworkWorkedEvent;delegate void NetworkCreatedEventHandler();static event NetworkCreatedEventHandler NetworkCreatedEvent;delegate void NetworkTrainedEventHandler();static event NetworkTrainedEventHandler NetworkTrainedEvent;OnTrainDataCreationComplete()

{++;(trainDataCreationCounter == trainDataCreationWorkAmount)

{(AllTrainDataCreationCompletedEvent != null)();

}

}OnNetworkTrained()

{++;(networkTrainCounter == networkTrainWorkAmount)

{(AllNetworkTrainedEvent != null)();

}

}OnNetworkCreated()

{++;(networkCreateCounter == networkCreateWorkAmount)

{(AllNetworkCreatedEvent != null)();= true;

}

}

#endregion СобытияNetworkController()

();=dbEngine.settingsTable.ReadSetting("initialDirectory");=false;=0;=0;=0;=-1;=-1;=-1;=8;=8;=8;">{.NetworkCreatedEvent += new NetworkController.NetworkCreatedEventHandler(this.OnNetworkCreated);.NetworkTrainedEvent += new NetworkController.NetworkTrainedEventHandler(this.OnNetworkTrained);.TrainDataCreatedEvent += new NeuralNetwork.TrainDataCreatedEventHandler(this.OnTrainDataCreationComplete);= new grabberMolotok.DBEngine.DBEngine();= new List();= dbEngine.settingsTable.ReadSetting("initialDirectory");= false;= 0;= 0;= 0;= -1;= -1;= -1;= 8;= 8;= 8;

}int GetNetworkCreationWorkAmount()

{networks = (new DirectoryInfo(initialDirectory + @"\64x48")).GetFiles("*.ann");networks.Length;

}CreateSmallNetworks()

{.Clear();.WriteLine("Инициализация нейронных сетей");networks = (new DirectoryInfo(initialDirectory + @"\64x48")).GetFiles("*.ann");= networks.Length;(var n in networks)

{watch = Stopwatch.StartNew();net = new NeuralNetwork(smallNetworkLayers);.Create(n.FullName);.TryParse(n.Name.Replace(".ann", ""), out net.id);.category = dbEngine.categoryTable.GetById(net.id);.Add(net);();.Stop();.WriteLine(((double)watch.ElapsedTicks / (double)Stopwatch.Frequency).ToString());

}= true;

}CreateBigNetworks()

{.Clear();networks = (new DirectoryInfo(initialDirectory + @"\400x300")).GetFiles("*.ann");(var n in networks)

{net = new NeuralNetwork(bigNetworkLayers);.Create(n.FullName);.TryParse(n.Name.Replace(".ann", ""), out net.id);.category = dbEngine.categoryTable.GetById(net.id);.Add(net);

}= true;

}

#region Паралельная инициализация сетейvoid ParallelCreateSmallNetworks()

networksFiles=newList();.AddRange(networksFilesArray);= networksFiles.Count;preparedList = ThreadHelper.SplitList(networksFiles, networkCreateThreadCount);(int counter = 0; counter < preparedList.Length; counter++)

{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 CreateSmallTrainDa