Git Product home page Git Product logo

Comments (5)

lightvector avatar lightvector commented on August 15, 2024

It would be messy to duplicate a new model file for every different possible model and have many versions of the code floating around that could then get out of sync with each other, so no this is not happening.

Perhaps the problem is not model_pytorch.py, but rather that you might not know how to look at the model file? You can see the full config for the model if you download a model file and load it in pytorch and look at the config:

data = torch.load(model_path,map_location="cpu")
print(data["config"])

The config contains a list of all the blocks in the model, in order, as well as the channel parameters and other settings. Every listed block in the model, like "bottlenest2", corresponds exactly to 1 "structure" in model_pytorch.py, which you can find if you search for that string in the code. So that should solve the problem with there being "various kinds of structures" - the config will let you determine precisely which ones are used. You can also iterate through the list of all the tensors in data["model"] to print their key and their shape, and see exactly the parameters.

from katago.

Nightbringers avatar Nightbringers commented on August 15, 2024

I'm trying to use b18c384nbt in my own python go_game. But i don't know what's the input of model. I first think it's same as AZ. But then i found it's total different. katago has two inputs, input_spatial and input_global. Is there a guide or example or something about the inputs?

from katago.

lightvector avatar lightvector commented on August 15, 2024

If you are simply trying to run KataGo from python because you want its suggested moves or analysis or ownership predictions, I recommend you ignore all of these details about the models and inputs and architectures. Just use query C++ analysis engine through subprocess:

Here is example code for doing that:
https://github.com/lightvector/KataGo/blob/master/python/query_analysis_engine_example.py

from katago.

Nightbringers avatar Nightbringers commented on August 15, 2024

I'm not just simply run KataGo from python. I want continue train model in python, use a different envs and MCTS. So i need to know the input of the model.

from katago.

lightvector avatar lightvector commented on August 15, 2024

Okay cool. In that case, take a look at https://github.com/lightvector/KataGo/blob/master/python/play.py - this is working code to load a neural net from python and query it based on a board position. It uses sgfmill for the board, and implements a basic GTP interface (https://www.lysator.liu.se/~gunnar/gtp/gtp2-spec-draft2/gtp2-spec.html) that will let you play on the command line with the bot which makes moves using the raw neural net (no MCTS).

The query to the neural net happens with the get_outputs function, where gs is a GameState (class defined right above that). The reason for having two different input tensors is that one holds spatial features (like where the stones are), and one holds global features that don't depend on the board position (like what the rules and komi are). These are computed by features.fill_row_features.

This is sort of old sandbox code that is mostly written a long time ago, so it's not very well commented or documented, so you'll have to do some work to trace the source code, but this should show you from start to end what the inference side of loading and running the net might look like purely from python.

Note that KataGo has no python MCTS implementation, so you're on your own there. This script only queries the raw net to make moves via the policy head directly. A lot of the graphical commands you see are designed for GoGUI, which is a particular gui you can try, which can view various outputs with graphical colors when this script is configured as the GTP engine for the gui.

from katago.

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.