我解析MNIST数据集在C#中的:http://yann.lecun.com/exdb/mnist/我在C#中用BinaryReader解析MNIST数据集有什么问题?
我试图读取二进制文件的第一Int32
:
FileStream fileS = new FileStream(fileName, FileMode.Open, FileAccess.Read);
BinaryReader reader = new BinaryReader(fileS);
int magicNumber = reader.ReadInt32();
但是,它给了我一个无感号码:50855936 。
如果我使用File.ReadAllBytes()
buffer = File.ReadAllBytes(fileName);
然后通过字节看,它工作正常(的前四个字节现在代表2049年),我在BinaryReader上做了什么错误?
文件格式如下(我想读第一幻数):
All the integers in the files are stored in the MSB first (high endian) format used by most non-Intel processors. Users of Intel processors and other low-endian machines must flip the bytes of the header.
训练集标签文件(列车标签-IDX1-UBYTE):
[offset] [type] [value] [description]
0000 32 bit integer 0x00000801(2049) magic number (MSB first)
0004 32 bit integer 60000 number of items
0008 unsignebyte ?? label
0009 unsigned byte ?? label
........
xxxx unsigned byte ?? label
The labels values are 0 to 9.d
你的文件是什么编码?默认情况下,BinaryReader使用UTF-8。 尝试在BinaryReader构造器调用中指定它,如果它不同于UTF-8。 – nestedloop
你能举一个你认为是错误的例子吗? –
endiannes问题? –