public void Reads() { string path; float[][] imagesData; int[] labels; const int nExamples = 10; CreateUSPSFile(out path, out imagesData, out labels, nExamples); using (USPSDatasetReader reader = new USPSDatasetReader(path)) { for (int i = 0; i < nExamples; ++i) { Assert.True(reader.HasNext(), "Reader should not be at the end"); IExample refExample = new NormalizedExample(imagesData[i], labels[i]); IExample readExample = reader.ReadNext(); Assert.True(Enumerable.SequenceEqual(refExample.Input, readExample.Input), "Written and read image data should be the same"); Assert.True(refExample.Target == readExample.Target, "Written and read labels should be the same"); } Assert.False(reader.HasNext(), "Reader should be at the end"); } File.Delete(path); }
public void Reads() { string[] paths; byte[][] imagesData; int[] labels; const int nFiles = 3; const int nExamplesPerFile = 4; const int nExamples = nFiles * nExamplesPerFile; CreateCIFAR10Files(out paths, out imagesData, out labels, nFiles, nExamplesPerFile); using (CIFAR10DatasetReader reader = new CIFAR10DatasetReader(paths)) { for (int i = 0; i < nExamples; ++i) { Assert.True(reader.HasNext(), "Reader should not be at the end"); IExample refExample = new NormalizedExample(imagesData[i], labels[i]); IExample readExample = reader.ReadNext(); Assert.True(Enumerable.SequenceEqual(refExample.Input, readExample.Input), "Written and read image data should be the same"); Assert.True(refExample.Target == readExample.Target, "Written and read labels should be the same"); } Assert.False(reader.HasNext(), "Reader should be at the end"); } foreach (string path in paths) { File.Delete(path); } }
public void NormalizesFromBytes() { byte[] data = new byte[DataLen]; int label = m_rand.Next(); m_rand.NextBytes(data); IExample example = new NormalizedExample(data, label); Assert.StrictEqual(example.Target, label); Assert.Equal(example.Input.Min(), 0, Precision); Assert.Equal(example.Input.Max(), 1, Precision); }
public void NormalizesFromFloats() { float[] data = new float[DataLen]; int label = m_rand.Next(); float multBy = m_rand.Next(1024); for (int i = 0; i < DataLen; ++i) { data[i] = (float)m_rand.NextDouble() * multBy; } IExample example = new NormalizedExample(data, label); Assert.StrictEqual(example.Target, label); Assert.Equal(example.Input.Min(), 0, Precision); Assert.Equal(example.Input.Max(), 1, Precision); }