private void ResizingRoutine_doWork(object sender, DoWorkEventArgs e)
        {
            resRandImgMapList.Clear();
            var rand       = new Random();
            var randomList = sourceImgMapList.OrderBy(x => rand.Next()).ToList();

            for (int i = 0; i < totalImgNum; i++)
            {
                Bitmap bm = null;
                try
                {
                    bm = new Bitmap(randomList[i].dir);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                }
                Bitmap rbm = CntkBitmapExtensions.Resize(
                    bm,
                    Convert.ToInt32(BindManager.BindMngr.ML_desWidth.value),
                    Convert.ToInt32(BindManager.BindMngr.ML_desHeight.value),
                    true);
                /// Redo dir, but keep the shuffled label
                imgMapStruct ims = new imgMapStruct()
                {
                    dir   = mlImgFolderArr[(int)jobType] + string.Format("\\{0:D5}.jpg", i),
                    label = randomList[i].label
                };

                resRandImgMapList.Add(ims);

                /// This is for creating mean file
                RGBList.Add(CntkBitmapExtensions.ExtractCHW(rbm));

                if (jobType == JobType.train)
                {
                    rbm = addPadding(rbm, 4);
                }

                rbm.Save(resRandImgMapList[i].dir);

                ResizingRoutine.ReportProgress(Convert.ToInt32((i + 1) * 100 / totalImgNum));
                Thread.Sleep(1);
                bm.Dispose();
                rbm.Dispose();
            }
        }
        private void loadLabels(string mapFileUrl)
        {
            sourceImgMapList.Clear();
            if (!File.Exists(mapFileUrl))
            {
                File.Create(mapFileUrl).Dispose();
                // Initalize
                for (int i = 0; i < totalImgNum; i++)
                {
                    imgMapStruct ims = new imgMapStruct()
                    {
                        dir   = string.Format(@"{0}\{1}", sourceImgFolderArr[(int)jobType], sourceImageInfo[i].Name),
                        label = 0
                    };
                    sourceImgMapList.Add(ims);
                }
                using (StreamWriter sw = new StreamWriter(mapFileUrl))
                {
                    for (int i = 0; i < totalImgNum; i++)
                    {
                        sw.WriteLine(string.Format("{0}\t{1}",
                                                   string.Format(@"{0}\{1}", mlImgFolderArr[(int)jobType], sourceImageInfo[i].Name),
                                                   sourceImgMapList[i].label));
                    }
                    sw.Dispose();
                }
            }
            else
            {
                using (StreamReader sr = File.OpenText(mapFileUrl))
                {
                    for (int i = 0; i < totalImgNum; i++)
                    {
                        string[] temp;
                        temp = sr.ReadLine().Split('\t');

                        imgMapStruct ims = new imgMapStruct()
                        {
                            dir   = temp[0],
                            label = Convert.ToInt32(temp[1])
                        };
                        sourceImgMapList.Add(ims);
                    }
                    sr.Dispose();
                }
            }
        }