Разработка автоматизированной системы классификации товаров по изображениям
Дипломная работа - Компьютеры, программирование
Другие дипломы по предмету Компьютеры, программирование
;void GetItems ()
{wB = new WebBrowser ();. ScriptErrorsSuppressed = true;pageCount = 0; ();url = this. url;. NavigateFromRequest (url);
{htmlPageCount = wB. WaitElement ("tabMainBox", 20000)
. GetInnerElements ("div", 0)
. GetInnerElements ("div", 0)
. GetInnerElements ("div", 0)
(\d*)", RegexOptions. IgnoreCase | RegexOptions.compiled);match = pageCountRegex. Match (htmlPageCount. OuterHtml);(match. Success)
{= Convert. ToInt32 (match. Groups [1]. Value);
}
}(NullReferenceException)
{= 1;
}(int i = 1; i <= pageCount; i++)
{(int tries = 0; tries < 5; tries++)
{
{
// Stopwatch watch = Stopwatch. StartNew ();. NavigateFromRequest ("
. GetInnerElements ("div", 1)
. GetInnerElements ("table", 0)
. GetInnerElements ("tbody", 0)
. GetInnerElements ("tr")
);
// watch. Stop ();
// Debug. WriteLine ( ( (double) watch. ElapsedTicks / (double) Stopwatch. Frequency). ToString ());;
}(NullReferenceException)
{. Sleep (50);
}
}
}(htmlItems);();
}
// /
// / Парсит товары в категории
// /
// /
// / itemsHtmlList)
{. WriteLine ("Начался парс товаров");itemIdRegex = new Regex ("data-id=\" ([\\d] *)", RegexOptions. IgnoreCase | RegexOptions.compiled);smallPicturesRegex = new Regex (@" (
{
// Stopwatch watch = Stopwatch. StartNew ();
/************************************/itemId = - 1; ();;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 }; // слои больших сетейtrainDataCreationCounter; // счетчик создания данных для обученияtrainDataCreationWorkAmount; // объём работы данных обученияtrainDataCreationThreadCount; // количество потоков данных обученияint TrainDataCreationThreadCount
{{ return trainDataCreationThreadCount; }{ trainDataCreationThreadCount = value; }
}networkTrainCounter; // счетчик обучения сетейnetworkTrainWorkAmount; // объём работы обучения сетейnetworkTrainThreadCount; // количество потоков обучения сетей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 ()
{. Clear ();networksFilesArray = (new DirectoryInfo (initialDirectory + @"\64x48")). GetFiles ("*. ann"); ();. AddRange (networksFilesArray);= networksFiles. Count;preparedList = ThreadHelper. SplitList (networksFiles, networkCreateThreadCount);(int counter = 0; counter < preparedList. Length; coun