MCPcopy Create free account
hub / github.com/tensorflow/tfjs-examples / getData_

Method getData_

mnist-acgan/data.js:152–186  ·  view source on GitHub ↗
(isTrainingData)

Source from the content-addressed store, hash-verified

150 }
151
152 getData_(isTrainingData) {
153 let imagesIndex;
154 let labelsIndex;
155 if (isTrainingData) {
156 imagesIndex = 0;
157 labelsIndex = 1;
158 } else {
159 imagesIndex = 2;
160 labelsIndex = 3;
161 }
162 const size = this.dataset[imagesIndex].length;
163 tf.util.assert(
164 this.dataset[labelsIndex].length === size,
165 `Mismatch in the number of images (${size}) and ` +
166 `the number of labels (${this.dataset[labelsIndex].length})`);
167
168 // Only create one big array to hold batch of images.
169 const imagesShape = [size, IMAGE_HEIGHT, IMAGE_WIDTH, 1];
170 const images = new Float32Array(tf.util.sizeFromShape(imagesShape));
171 const labels = new Int32Array(tf.util.sizeFromShape([size, 1]));
172
173 let imageOffset = 0;
174 let labelOffset = 0;
175 for (let i = 0; i < size; ++i) {
176 images.set(this.dataset[imagesIndex][i], imageOffset);
177 labels.set(this.dataset[labelsIndex][i], labelOffset);
178 imageOffset += IMAGE_FLAT_SIZE;
179 labelOffset += 1;
180 }
181
182 return {
183 images: tf.tensor4d(images, imagesShape),
184 labels: tf.oneHot(tf.tensor1d(labels, 'int32'), LABEL_FLAT_SIZE).toFloat()
185 };
186 }
187}
188
189module.exports = new MnistDataset();

Callers 2

getTrainDataMethod · 0.95
getTestDataMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected