GithubHelp home page GithubHelp logo

mnistdb-java's Introduction

mnistdb-java

java implementation for mnist handwritten db

http://yann.lecun.com/exdb/mnist/

prerequisite

  • jdk(or jre) 1.8+
  • mnist database file

how to use

    public static void main(String[] args) {
        
        String label_file_path = "path to label file";
        String image_file_path = "path to image file";
        MnistDb trainingdb = MnistUtil.loadDb(label_file_path, image_file_path);
        
        System.out.println("# of samples : " + trainingdb.size());
        
        Mnistlet firstImage = trainingdb.get(0); // is '5'
        System.out.println();
        System.out.println("[first image info]");
        System.out.println("index    : " + firstImage.index());
        System.out.println("number   : " + firstImage.number());
        System.out.println("raw bytes: " + Arrays.toString(firstImage.rawbytes()));
        
        Mnistlet last = trainingdb.get(trainingdb.size() - 1);
        System.out.println();
        System.out.println("[last image info]");
        System.out.println("index    : " + last.index());
        System.out.println("number   : " + last.number());
        System.out.println("raw bytes: " + Arrays.toString(last.rawbytes()));
    }

query by range

  • iteration style
    public static void main ( String [] args ) {
        String label_file_path = "....";
        String image_file_path = "....";
        MnistDb db = MnistUtil.loadDb(label_file_path, image_file_path);
        
        int startIndex = 10; // inclusive
        int endIndex = 20;   // exclusive
        MnistLoop loop = db.queryByRange(startIndex, endIndex);
        
        for ( Mnistlet mlet : loop ) {
            System.out.println(String.format("index:%3d, number: '%s'", mlet.index(), mlet.number()));
            // mlet.rawbytes();
        }
    }
    
  • index style
    public static void main ( String [] args ) {
        String label_file_path = "....";
        String image_file_path = "....";
        MnistDb db = MnistUtil.loadDb(label_file_path, image_file_path);
        
        int startIndex = 10; // inclusive
        int endIndex = 20;   // exclusive
        MnistLoop loop = db.queryByRange(startIndex, endIndex);
        
        for ( int i = 0 ; i < loop.size(); i++ ) {
            Mnistlet mlet = loop.get(i);
            System.out.println(String.format("index:%3d, number: '%s'", mlet.index(), mlet.number()));
        }
    }
    

query by number

    public static void main(String[] args) {
        
        String label_file_path = "....";
        String image_file_path = "....";
        MnistDb db = MnistUtil.loadDb(label_file_path, image_file_path);
        
        MnistLoop loop = db.queryByNum('9');
        
        System.out.println(String.format("db has %d of '9'", loop.size()));
        for( Mnistlet nine : loop ) {
            System.out.println("found at " + nine.index());
        }
    }

mnistdb-java's People

Contributors

yeori avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.