onLoadFile¶
-
MNIST.
onLoadFile
(file_name, data)¶ ファイル読み込み完了時の処理
ソース¶
onLoadFile(file_name, data) {
var type, cnt, h, w;
if (file_name.indexOf("-images") != -1) {
// 画像の場合
type = this.BytesToInt(data, 0);
// データ数
cnt = this.BytesToInt(data, 4);
// 画像の高さ
h = this.BytesToInt(data, 8);
// 画像の幅
w = this.BytesToInt(data, 12);
Assert(16 + cnt * h * w == data.length);
if (file_name.startsWith("train-images")) {
// トレーニングの画像の場合
this.trainingDataImage = data.slice(16);
this.trainingImgCnt = cnt;
this.imgH = h;
this.imgW = w;
this.imgIdx = 0;
setTimeout(this.DrawImage.bind(this), 100);
}
else {
// テストの画像の場合
this.testDataImage = data.slice(16);
this.testImgCnt = cnt;
}
console.log("画像 name:%s len:%d type:%d cnt:%d H:%d W:%d", file_name, data.length, type, cnt, h, w);
}
else if (file_name.indexOf("-labels") != -1) {
// ラベルの場合
type = this.BytesToInt(data, 0);
// データ数
cnt = this.BytesToInt(data, 4);
Assert(8 + cnt == data.length);
console.log("ラベル name:%s len:%d type:%d cnt:%d", file_name, data.length, type, cnt);
if (file_name.startsWith("train-labels")) {
// トレーニングのラベルの場合
this.trainingDataLabel = data.slice(8);
}
else {
// テストのラベルの場合
this.testDataLabel = data.slice(8);
}
}
if (this.trainingDataImage && this.trainingDataLabel && this.testDataImage && this.testDataLabel) {
this.trainingData = this.makeXY(this.trainingImgCnt, this.trainingDataImage, this.trainingDataLabel);
this.testData = this.makeXY(this.testImgCnt , this.testDataImage , this.testDataLabel);
}
}