Giter Site home page Giter Site logo

Comments (3)

hughperkins avatar hughperkins commented on June 1, 2024

Well... you just need to create an appropriate input tensor, and send that in, using the python api, or the c++ api, or via the commandline. What language are you using for your prediction? If python, then you would do something like:

(adapted from https://github.com/hughperkins/DeepCL/blob/master/python/test_lowlevel.py)

inputTensor = array.array('f', [0] * (numPlanes * boardSize * boardSize))
# ... populate the inputTensor somehow ... , and then
net.forward(inputTensor)
lastLayer = net.getLastLayer()
predictions = lastLayer.getLabels()

from deepcl.

 avatar commented on June 1, 2024

Thank you for your response. For now I use commandline to do prediction, i tried make a DAT file as inputTensor with single SGF file from kgsgo-dataset-preprocessorv2. and add header
mlv2-n=1-numplanes=7-imagewidth=19-imageheight=19-datatype=int-bpp=1
to the DAT file, Which n i assume it to 1 because I make the DAT file with single SGF file and one move only. After I do prediction with commandline. it shows n entries data, each entry has 361 numfield.

My question is the 361 numfield that possible is the probability of the SGF's next move on go game?
Thank you for your help!

from deepcl.

hughperkins avatar hughperkins commented on June 1, 2024

Ok, the n is indeed the number of examples in the file. From src/loaders/Kgsv2Loader.cpp:

    int N = atoi(split(split(headerString, "-n=")[1], "-")[0]);
    int numPlanes = atoi(split(split(headerString, "-numplanes=")[1], "-")[0]);
    int imageSize = atoi(split(split(headerString, "-imagewidth=")[1], "-")[0]);
    int imageSizeRepeated = atoi(split(split(headerString, "-imageheight=")[1], "-")[0]);
   ...
    if(numRecords == 0) {
        numRecords = N - startRecord;
    }
   ...
    for(int n = 0; n < numRecords; n++) {
     ...
   }

As far as the output, the relevant code is in src/main/predict.cpp:

        if(!config.writeLabels) {
            if(config.outputFormat == "text") {
                float const*output = net->getLayer(config.outputLayer)->getOutput();
                const int numFields = net->getLayer(config.outputLayer)->getOutputCubeSize();
                for(int i = 0; i < config.batchSize; i++) {
                    for(int f = 0; f < numFields; f++) {
                        if(f > 0) {
                            *outFile << " ";
                        }
                        *outFile << output[ i * numFields + f ];
                    }
                    *outFile << "\n";
                }
            } else {
                outFile->write(reinterpret_cast<const char *>(net->getOutput()), net->getOutputNumElements() * 4 * config.batchSize);
            }
        } else {
            SoftMaxLayer *softMaxLayer = dynamic_cast< SoftMaxLayer *>(net->getLayer(config.outputLayer) );
            if(softMaxLayer == 0) {
                cout << "must choose softmaxlayer, if want to output labels" << endl;
                return;
            }
            softMaxLayer->getLabels(labels);
            if(config.outputFormat == "text") {
                for(int i = 0; i < config.batchSize; i++) {
                    *outFile << labels[i] << "\n";
                }
            } else {
                outFile->write(reinterpret_cast< char * >(labels), config.batchSize * 4l);
            }
            outFile->flush();
        }
  • if config.writeLabels is 1, it's going to write one label per example, one for each of the batchsize examples
  • otherwise, as you say, its going to write hte output of the final softmax layer. Each line will contain the output probability distribution for one sample in the minibatch

from deepcl.

Related Issues (20)

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.