Exemple #1
0
 static void Main(string[] args)
 {
     string testDbPath = @"c:\Users\unbornchikken\Documents\x\Gender\T_gender_20x24.pdb.pat";
     string trainingDbPath = @"c:\Users\unbornchikken\Documents\x\Gender\L_gender_20x24.pdb.pat";
     int count = 0;
     int freq = 1000;
     using (var testFile = File.OpenRead(testDbPath))
     using (var trainingFile = File.OpenRead(trainingDbPath))
     using (var ctx = new GenderEntities())
     {
         var list = new LinkedList<Item>();
         ctx.DeleteAll();
         var testReader = new RawGenderItemReader(testFile, false);
         var trainingReader = new RawGenderItemReader(trainingFile, true);
         int all = testReader.ItemCount + trainingReader.ItemCount;
         foreach (var item in testReader.ReadItems().Concat(trainingReader.ReadItems()))
         {
             ctx.AddToItems(item);
             list.AddLast(item);
             if (++count % freq == 0)
             {
                 Console.WriteLine("{0} / {1}", count, all);
                 ctx.SaveChanges();
                 Detach(ctx, list);
             }
         }
         ctx.SaveChanges();
     }
     Console.ReadKey();
 }
        public override Script this[int index]
        {
            get
            {
                Contract.Requires(index >= 0 && index < Count);

                if (indexMap.Count != Count) throw new InvalidOperationException("Gender Script provider is not initialized.");

                using (var ctx = new GenderEntities())
                {
                    index = indexMap[index];
                    var item = ctx.Items.Where(i => i.ID == index).First();
                    return CreateScript(item);
                }
            }
        }
        public override IEnumerable<Script> GetScripts(ISet<int> indexes)
        {
            if (indexMap.Count != Count) throw new InvalidOperationException("Gender Script provider is not initialized.");

            int miIdx = 0;
            var mappedIndexes = new int[indexes.Count];
            foreach (int index in indexes)
            {
                mappedIndexes[miIdx++] = indexMap[index];
            }
            
            using (var ctx = new GenderEntities())
            {
                var q = ctx.Items.Where(i => mappedIndexes.Contains(i.ID));
                foreach (var item in q)
                {
                    yield return CreateScript(item);
                }
            }
        }
        public void Update()
        {
            using (var ctx = new GenderEntities())
            {
                ObjectQuery<Item> q = null;
                if (TestSetType == GenderTestSet.All) q = ctx.Items;
                else if (TestSetType == GenderTestSet.Training) q = (ObjectQuery<Item>)ctx.Items.Where(i => i.IsTrainingPattern);
                else if (TestSetType == GenderTestSet.Validation) q = (ObjectQuery<Item>)ctx.Items.Where(i => !i.IsTrainingPattern);
                var result = q.Execute(MergeOption.NoTracking);

                int count = 0;
                int passed = 0;
                int failed = 0;
                foreach (var item in result)
                {
                    bool gender = Computation.ComputeGender(item.Pixels);
                    if (gender == item.Gender) passed++; else failed++;
                    count++;
                }
                TestedItems = count;
                PassedItems = passed;
                FailedItems = failed;
            }
        }
Exemple #5
0
 private static void Detach(GenderEntities ctx, LinkedList<Item> list)
 {
     foreach (var item in list) ctx.Items.Detach(item);
     list.Clear();
 }
        public override void Reinitialize()
        {
            indexMap.Clear();
            using (var ctx = new GenderEntities())
            {
                var q = isTraining ? ctx.Items.Where(i => i.IsTrainingPattern) : ctx.Items.Where(i => !i.IsTrainingPattern);
                var dbIdxEnum = q.Select(i => i.ID).AsEnumerable().OrderByRandom().GetEnumerator();
                for (int idx = 0; idx < count && dbIdxEnum.MoveNext(); idx++)
                {
                    indexMap.Add(idx, dbIdxEnum.Current);
                }
                count = indexMap.Count;
            }

            if (isTraining) Console.WriteLine("Training reinitialized."); else Console.WriteLine("Validation reinitialized.");
        }