Skip to content

VGG'11 model on FashionMNIST dataset #16

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jul 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion tensorflow-examples/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
<archive>
<manifest>
<mainClass>
org.tensorflow.model.examples.mnist.SimpleMnist
org.tensorflow.model.examples.dense.SimpleMnist
</mainClass>
</manifest>
</archive>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
/*
* Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright 2020 The TensorFlow Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* =======================================================================
*/
package org.tensorflow.model.examples.mnist;
package org.tensorflow.model.examples.cnn.lenet;

import java.util.Arrays;
import java.util.logging.Level;
Expand All @@ -22,8 +23,8 @@
import org.tensorflow.Operand;
import org.tensorflow.Session;
import org.tensorflow.Tensor;
import org.tensorflow.model.examples.mnist.data.ImageBatch;
import org.tensorflow.model.examples.mnist.data.MnistDataset;
import org.tensorflow.model.examples.datasets.ImageBatch;
import org.tensorflow.model.examples.datasets.mnist.MnistDataset;
import org.tensorflow.op.Op;
import org.tensorflow.op.Ops;
import org.tensorflow.op.core.Constant;
Expand Down Expand Up @@ -76,6 +77,11 @@ public class CnnMnist {
public static final String TRAINING_LOSS = "training_loss";
public static final String INIT = "init";

private static final String TRAINING_IMAGES_ARCHIVE = "mnist/train-images-idx3-ubyte.gz";
private static final String TRAINING_LABELS_ARCHIVE = "mnist/train-labels-idx1-ubyte.gz";
private static final String TEST_IMAGES_ARCHIVE = "mnist/t10k-images-idx3-ubyte.gz";
private static final String TEST_LABELS_ARCHIVE = "mnist/t10k-labels-idx1-ubyte.gz";

public static Graph build(String optimizerName) {
Graph graph = new Graph();

Expand Down Expand Up @@ -294,7 +300,8 @@ public static void main(String[] args) {
logger.info(
"Usage: MNISTTest <num-epochs> <minibatch-size> <optimizer-name>");

MnistDataset dataset = MnistDataset.create(0);
MnistDataset dataset = MnistDataset.create(0, TRAINING_IMAGES_ARCHIVE, TRAINING_LABELS_ARCHIVE,
TEST_IMAGES_ARCHIVE, TEST_LABELS_ARCHIVE);

logger.info("Loaded data.");

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* Copyright 2020 The TensorFlow Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* =======================================================================
*/
package org.tensorflow.model.examples.cnn.vgg;

import org.tensorflow.model.examples.datasets.mnist.MnistDataset;

import java.util.logging.Logger;

/**
* Trains and evaluates VGG'11 model on FashionMNIST dataset.
*/
public class VGG11OnFashionMNIST {
// Hyper-parameters
public static final int EPOCHS = 1;
public static final int BATCH_SIZE = 500;

// Fashion MNIST dataset paths
public static final String TRAINING_IMAGES_ARCHIVE = "fashionmnist/train-images-idx3-ubyte.gz";
public static final String TRAINING_LABELS_ARCHIVE = "fashionmnist/train-labels-idx1-ubyte.gz";
public static final String TEST_IMAGES_ARCHIVE = "fashionmnist/t10k-images-idx3-ubyte.gz";
public static final String TEST_LABELS_ARCHIVE = "fashionmnist/t10k-labels-idx1-ubyte.gz";

private static final Logger logger = Logger.getLogger(VGG11OnFashionMNIST.class.getName());

public static void main(String[] args) {
logger.info("Data loading.");
MnistDataset dataset = MnistDataset.create(0, TRAINING_IMAGES_ARCHIVE, TRAINING_LABELS_ARCHIVE, TEST_IMAGES_ARCHIVE, TEST_LABELS_ARCHIVE);

try (VGGModel vggModel = new VGGModel()) {
logger.info("Model training.");
vggModel.train(dataset, EPOCHS, BATCH_SIZE);

logger.info("Model evaluation.");
vggModel.test(dataset, BATCH_SIZE);
}
}
}
Loading