LeelaChessZero / lczero-training

For code etc relating to the network training process.
143 stars 119 forks source link

How to load the weight pb file to tensorflow model? #221

Closed tianyu-z closed 8 months ago

tianyu-z commented 8 months ago

Hi, I followed readme and put the downloaded pb file "192x15-2022_0418_1738_54_779.pb" to the example.yaml training:path.

It always raises error: This is the tensorflow code to read proto model. However, I always get file decoding error: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xc0 in position 1: invalid start byte

May I know that how to load the pb file correctly?

Thank you!

mooskagh commented 8 months ago

The Lc0 weights format is different from what TF uses, so it cannot be opened directly.

However, if you convert the weights to the ONNX format, it will likely be usable in tensorflow.

To convert Leela weights into the ONNX format, run: ./lc0 leela2onnx --input=path/to/weights.pb.gzip --output=path/to/model.onnx

After that you can e.g. explore the model using the Netron app (https://netron.app/, also pip install netron to install locally), or try to import into one of neural network frameworks (pytorch, tensorflow, etc) and use there.

If you have any further questions, I'd recommend to join our Discord chat at http://lc0.org/chat, and ask there in the #help channel.