private void CheckIfSomethingChaged(MNISTSetType type, int[] validNumbers, bool randomEnumerate, bool defineOrder) { if (lastType != type || lastValidNumbers != validNumbers || lastRandomEnumerate != randomEnumerate || lastDefineOrder != defineOrder) { lastType = type; lastValidNumbers = validNumbers; lastRandomEnumerate = randomEnumerate; lastDefineOrder = defineOrder; initialized = false; } }
/// <summary> /// Gets the next values /// </summary> /// <param name="validNumbers">Array of integers, you want the selection restrict to.</param> /// <returns>Array of arrays of floats, in which the values is encoded.</returns> public MyMNISTImage GetNextImage(int[] validNumbers, MNISTSetType setType) { ArrayList images = null; IEnumerator enumerator = null; int examplesPerDigitCnt = 0; if (setType == MNISTSetType.Training) { images = m_trainingImages; enumerator = m_trainingImagesEnumerator; examplesPerDigitCnt = m_trainingExamplesPerDigitCnt; } else if (setType == MNISTSetType.Test) { images = m_testImages; enumerator = m_testImagesEnumerator; examplesPerDigitCnt = m_testExamplesPerDigitCnt; } if (RandomEnumerate) { MyMNISTImage im = (MyMNISTImage)images[rand.Next(Math.Min(examplesPerDigitCnt * 10, images.Count))]; // choose random image until it is in the validNumbers set; // if "sequence ordered" is ON it also has to be the expected next number in given sequence if (m_definedOrder && im.Label != validNumbers[m_sequenceIterator] || !validNumbers.Contains(im.Label)) { return this.GetNextImage(validNumbers, setType); } m_sequenceIterator = (m_sequenceIterator + 1) % validNumbers.Length; return im; } else if (enumerator.MoveNext() && m_imagesServed < images.Count) { MyMNISTImage im = (MyMNISTImage)enumerator.Current; m_imagesServed++; if (m_definedOrder) { if (im.Label != validNumbers[m_sequenceIterator]) { return GetNextImage(validNumbers, setType); } m_sequenceIterator = (m_sequenceIterator + 1) % validNumbers.Length; } else { if (!validNumbers.Contains(im.Label)) { return GetNextImage(validNumbers, setType); } } return im; } else { switch (m_afterLastImage) { case MNISTLastImageMethod.ResetToStart: { enumerator.Reset(); m_imagesServed = 0; // Hack return GetNextImage(validNumbers, setType); } case MNISTLastImageMethod.SendNothing: { return m_blankImage; } default: { return GetNextImage(validNumbers, setType); } } } }
/// <summary> /// Gets the next values /// </summary> /// <param name="validNumbers">Array of integers, you want the selection restrict to.</param> /// <returns>Array of arrays of floats, in which the values is encoded.</returns> public MyMNISTImage GetNextImage(int[] validNumbers, MNISTSetType setType) { ArrayList images = null; IEnumerator enumerator = null; int examplesPerDigitCnt = 0; if (setType == MNISTSetType.Training) { images = m_trainingImages; enumerator = m_trainingImagesEnumerator; examplesPerDigitCnt = m_trainingExamplesPerDigitCnt; } else if (setType == MNISTSetType.Test) { images = m_testImages; enumerator = m_testImagesEnumerator; examplesPerDigitCnt = m_testExamplesPerDigitCnt; } if (RandomEnumerate) { MyMNISTImage im = (MyMNISTImage)images[rand.Next(Math.Min(examplesPerDigitCnt * 10, images.Count))]; // choose random image until it is in the validNumbers set; // if "sequence ordered" is ON it also has to be the expected next number in given sequence if (m_definedOrder && im.Label != validNumbers[m_sequenceIterator] || !validNumbers.Contains(im.Label)) { return(this.GetNextImage(validNumbers, setType)); } m_sequenceIterator = (m_sequenceIterator + 1) % validNumbers.Length; return(im); } else if (enumerator.MoveNext() && m_imagesServed < images.Count) { MyMNISTImage im = (MyMNISTImage)enumerator.Current; m_imagesServed++; if (m_definedOrder) { if (im.Label != validNumbers[m_sequenceIterator]) { return(GetNextImage(validNumbers, setType)); } m_sequenceIterator = (m_sequenceIterator + 1) % validNumbers.Length; } else { if (!validNumbers.Contains(im.Label)) { return(GetNextImage(validNumbers, setType)); } } return(im); } else { switch (m_afterLastImage) { case MNISTLastImageMethod.ResetToStart: { enumerator.Reset(); m_imagesServed = 0; // Hack return(GetNextImage(validNumbers, setType)); } case MNISTLastImageMethod.SendNothing: { return(m_blankImage); } default: { return(GetNextImage(validNumbers, setType)); } } } }
/// <summary> /// Gets the next values /// </summary> /// <param name="validNumbers">Array of integers, you want the selection restrict to.</param> /// <returns>Array of arrays of floats, in which the values is encoded.</returns> public MyMNISTImage GetNextImage(int[] validNumbers, MNISTSetType setType) { MyMNISTImage imageToReturn = null; ArrayList images = null; IEnumerator enumerator = null; int examplesPerDigitCnt = 0; if (setType == MNISTSetType.Training) { images = m_trainingImages; enumerator = m_trainingImagesEnumerator; examplesPerDigitCnt = m_trainingExamplesPerDigitCnt; } else if (setType == MNISTSetType.Test) { images = m_testImages; enumerator = m_testImagesEnumerator; examplesPerDigitCnt = m_testExamplesPerDigitCnt; } CheckIfSomethingChaged(setType, validNumbers, RandomEnumerate, m_definedOrder); if (!initialized) { initialized = true; //indicates whether this particular image was already shown. This prevents the situation that some numbers start to repeat while others do not appear on the output alreadyShown = new bool[examplesPerDigitCnt * 10]; for (int i = 0; i < alreadyShown.Length; i++) { alreadyShown[i] = false; } //how many images to show until the set starts to repeat again howManyLeft = examplesPerDigitCnt * validNumbers.Length; m_sequenceIterator = 0; m_lastServedImage = -1; } if (RandomEnumerate) { m_lastServedImage = rand.Next(Math.Min(examplesPerDigitCnt * 10, images.Count)); MyMNISTImage im = (MyMNISTImage)images[m_lastServedImage]; // choose random image until it is in the validNumbers set; // if "sequence ordered" is ON it also has to be the expected next number in given sequence if ((m_definedOrder && im.Label != validNumbers[m_sequenceIterator]) || !validNumbers.Contains(im.Label)) { return this.GetNextImage(validNumbers, setType); } imageToReturn = im; } else { MyMNISTImage im = null; while (enumerator.MoveNext() && m_lastServedImage < images.Count - 1) { im = (MyMNISTImage)enumerator.Current; m_lastServedImage++; if (m_definedOrder) { if (im.Label == validNumbers[m_sequenceIterator]) { imageToReturn = im; break; } } else { if (validNumbers.Contains(im.Label)) { imageToReturn = im; break; } } } if (imageToReturn == null) { switch (m_afterLastImage) { case MNISTLastImageMethod.ResetToStart: { enumerator.Reset(); m_lastServedImage = -1; return GetNextImage(validNumbers, setType); } case MNISTLastImageMethod.SendNothing: { return m_blankImage; } default: { return GetNextImage(validNumbers, setType); } } } } if (alreadyShown[m_lastServedImage]) { return this.GetNextImage(validNumbers, setType); } else { DecreaseLeftCounter(m_lastServedImage, examplesPerDigitCnt * validNumbers.Length); m_sequenceIterator = (m_sequenceIterator + 1) % validNumbers.Length; return imageToReturn; } }
/// <summary> /// Gets the next values /// </summary> /// <param name="validNumbers">Array of integers, you want the selection restrict to.</param> /// <returns>Array of arrays of floats, in which the values is encoded.</returns> public MyMNISTImage GetNextImage(int[] validNumbers, MNISTSetType setType) { MyMNISTImage imageToReturn = null; ArrayList images = null; IEnumerator enumerator = null; int examplesPerDigitCnt = 0; if (setType == MNISTSetType.Training) { images = m_trainingImages; enumerator = m_trainingImagesEnumerator; examplesPerDigitCnt = m_trainingExamplesPerDigitCnt; } else if (setType == MNISTSetType.Test) { images = m_testImages; enumerator = m_testImagesEnumerator; examplesPerDigitCnt = m_testExamplesPerDigitCnt; } CheckIfSomethingChaged(setType, validNumbers, RandomEnumerate, m_definedOrder); if (!initialized) { initialized = true; //indicates whether this particular image was already shown. This prevents the situation that some numbers start to repeat while others do not appear on the output alreadyShown = new bool[examplesPerDigitCnt * 10]; for (int i = 0; i < alreadyShown.Length; i++) { alreadyShown[i] = false; } //how many images to show until the set starts to repeat again howManyLeft = examplesPerDigitCnt * validNumbers.Length; m_sequenceIterator = 0; m_lastServedImage = -1; } if (RandomEnumerate) { m_lastServedImage = rand.Next(Math.Min(examplesPerDigitCnt * 10, images.Count)); MyMNISTImage im = (MyMNISTImage)images[m_lastServedImage]; // choose random image until it is in the validNumbers set; // if "sequence ordered" is ON it also has to be the expected next number in given sequence if ((m_definedOrder && im.Label != validNumbers[m_sequenceIterator]) || !validNumbers.Contains(im.Label)) { return(this.GetNextImage(validNumbers, setType)); } imageToReturn = im; } else { MyMNISTImage im = null; while (enumerator.MoveNext() && m_lastServedImage < images.Count - 1) { im = (MyMNISTImage)enumerator.Current; m_lastServedImage++; if (m_definedOrder) { if (im.Label == validNumbers[m_sequenceIterator]) { imageToReturn = im; break; } } else { if (validNumbers.Contains(im.Label)) { imageToReturn = im; break; } } } if (imageToReturn == null) { switch (m_afterLastImage) { case MNISTLastImageMethod.ResetToStart: { enumerator.Reset(); m_lastServedImage = -1; return(GetNextImage(validNumbers, setType)); } case MNISTLastImageMethod.SendNothing: { return(m_blankImage); } default: { return(GetNextImage(validNumbers, setType)); } } } } if (alreadyShown[m_lastServedImage]) { return(this.GetNextImage(validNumbers, setType)); } else { DecreaseLeftCounter(m_lastServedImage, examplesPerDigitCnt * validNumbers.Length); m_sequenceIterator = (m_sequenceIterator + 1) % validNumbers.Length; return(imageToReturn); } }