public static Data load_cifar10_data(string filename) { Data d = new Data(); d.Shallow = 0; long i, j; Matrix x = new Matrix(10000, 3072); Matrix y = new Matrix(10000, 10); d.X = x; d.Y = y; if (!File.Exists(filename)) { Utils.file_error(filename); } using (var stream = File.OpenRead(filename)) { for (i = 0; i < 10000; ++i) { var bytes = new byte[3073]; stream.Read(bytes, 0, bytes.Length); int sclass = bytes[0]; y.Vals[i][sclass] = 1; for (j = 0; j < x.Cols; ++j) { x.Vals[i][j] = bytes[j + 1]; } } } d.scale_data_rows(1.0f / 255); return(d); }
public static Data load_all_cifar10() { Data d = new Data(); d.Shallow = 0; int i, j, b; Matrix x = new Matrix(50000, 3072); Matrix y = new Matrix(50000, 10); d.X = x; d.Y = y; for (b = 0; b < 5; ++b) { var buff = $"Data/cifar/cifar-10-batches-bin/data_batch_{b + 1}.bin"; if (!File.Exists(buff)) { Utils.file_error(buff); } using (var fstream = File.OpenRead(buff)) { for (i = 0; i < 10000; ++i) { var bytes = new byte[3073]; fstream.Read(bytes, 0, bytes.Length); int sclass = bytes[0]; y.Vals[i + b * 10000][sclass] = 1; for (j = 0; j < x.Cols; ++j) { x.Vals[i + b * 10000][j] = bytes[j + 1]; } } } } d.scale_data_rows(1.0f / 255); d.smooth_data(); return(d); }