NeymarL / ChineseChess-AlphaZero

Implement AlphaZero/AlphaGo Zero methods on Chinese chess.
https://cczero.org
GNU General Public License v3.0
1.06k stars 339 forks source link

[Error] Self paly with flag --ucci raising error #28

Closed CharlesLiuyx closed 5 years ago

CharlesLiuyx commented 5 years ago

After install the requirements, I typed the python cchess_alphazero/run.py play

I got this error raised

Traceback (most recent call last):
  File "/home/yaoxingliu/.conda/envs/tensorflow/lib/python3.6/site-packages/tensorflow/python/framework/ops.py", line 1626, in _create_c_op
    c_op = c_api.TF_FinishOperation(op_desc)
tensorflow.python.framework.errors_impl.InvalidArgumentError: Shape must be rank 1 but is rank 0 for 'input_batchnorm/cond/Reshape_4' (op: 'Reshape') with input shapes: [1,192,1,1], [].

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "cchess_alphazero/run.py", line 14, in <module>
    manager.start()
  File "/media/yaoxingliu/Project/DeepLearning/ChineseChess-AlphaZero/cchess_alphazero/manager.py", line 93, in start
    play.start(config, not args.ai_move_first)
  File "/media/yaoxingliu/Project/DeepLearning/ChineseChess-AlphaZero/cchess_alphazero/play_games/play.py", line 36, in start
    play.start(human_move_first)
  File "/media/yaoxingliu/Project/DeepLearning/ChineseChess-AlphaZero/cchess_alphazero/play_games/play.py", line 100, in start
    self.load_model()
  File "/media/yaoxingliu/Project/DeepLearning/ChineseChess-AlphaZero/cchess_alphazero/play_games/play.py", line 64, in load_model
    if self.config.opts.new or not load_best_model_weight(self.model):
  File "/media/yaoxingliu/Project/DeepLearning/ChineseChess-AlphaZero/cchess_alphazero/lib/model_helper.py", line 13, in load_best_model_weight
    return model.load(model.config.resource.model_best_config_path, model.config.resource.model_best_weight_path)
  File "/media/yaoxingliu/Project/DeepLearning/ChineseChess-AlphaZero/cchess_alphazero/agent/model.py", line 99, in load
    self.model = Model.from_config(json.load(f))
  File "/home/yaoxingliu/.conda/envs/tensorflow/lib/python3.6/site-packages/keras/engine/network.py", line 1032, in from_config
    process_node(layer, node_data)
  File "/home/yaoxingliu/.conda/envs/tensorflow/lib/python3.6/site-packages/keras/engine/network.py", line 991, in process_node
    layer(unpack_singleton(input_tensors), **kwargs)
  File "/home/yaoxingliu/.conda/envs/tensorflow/lib/python3.6/site-packages/keras/engine/base_layer.py", line 457, in __call__
    output = self.call(inputs, **kwargs)
  File "/home/yaoxingliu/.conda/envs/tensorflow/lib/python3.6/site-packages/keras/layers/normalization.py", line 206, in call
    training=training)
  File "/home/yaoxingliu/.conda/envs/tensorflow/lib/python3.6/site-packages/keras/backend/tensorflow_backend.py", line 3123, in in_train_phase
    x = switch(training, x, alt)
  File "/home/yaoxingliu/.conda/envs/tensorflow/lib/python3.6/site-packages/keras/backend/tensorflow_backend.py", line 3058, in switch
    else_expression_fn)
  File "/home/yaoxingliu/.conda/envs/tensorflow/lib/python3.6/site-packages/tensorflow/python/util/deprecation.py", line 488, in new_func
    return func(*args, **kwargs)
  File "/home/yaoxingliu/.conda/envs/tensorflow/lib/python3.6/site-packages/tensorflow/python/ops/control_flow_ops.py", line 2087, in cond
    orig_res_f, res_f = context_f.BuildCondBranch(false_fn)
  File "/home/yaoxingliu/.conda/envs/tensorflow/lib/python3.6/site-packages/tensorflow/python/ops/control_flow_ops.py", line 1920, in BuildCondBranch
    original_result = fn()
  File "/home/yaoxingliu/.conda/envs/tensorflow/lib/python3.6/site-packages/keras/layers/normalization.py", line 167, in normalize_inference
    epsilon=self.epsilon)
  File "/home/yaoxingliu/.conda/envs/tensorflow/lib/python3.6/site-packages/keras/backend/tensorflow_backend.py", line 1908, in batch_normalization
    mean = tf.reshape(mean, (-1))
  File "/home/yaoxingliu/.conda/envs/tensorflow/lib/python3.6/site-packages/tensorflow/python/ops/gen_array_ops.py", line 6296, in reshape
    "Reshape", tensor=tensor, shape=shape, name=name)
  File "/home/yaoxingliu/.conda/envs/tensorflow/lib/python3.6/site-packages/tensorflow/python/framework/op_def_library.py", line 787, in _apply_op_helper
    op_def=op_def)
  File "/home/yaoxingliu/.conda/envs/tensorflow/lib/python3.6/site-packages/tensorflow/python/util/deprecation.py", line 488, in new_func
    return func(*args, **kwargs)
  File "/home/yaoxingliu/.conda/envs/tensorflow/lib/python3.6/site-packages/tensorflow/python/framework/ops.py", line 3272, in create_op
    op_def=op_def)
  File "/home/yaoxingliu/.conda/envs/tensorflow/lib/python3.6/site-packages/tensorflow/python/framework/ops.py", line 1790, in __init__
    control_input_ops)
  File "/home/yaoxingliu/.conda/envs/tensorflow/lib/python3.6/site-packages/tensorflow/python/framework/ops.py", line 1629, in _create_c_op
    raise ValueError(str(e))
ValueError: Shape must be rank 1 but is rank 0 for 'input_batchnorm/cond/Reshape_4' (op: 'Reshape') with input shapes: [1,192,1,1], [].
CharlesLiuyx commented 5 years ago

Env bugs solved

CharlesLiuyx commented 5 years ago

When I try to use python cchess_alphazero/run.py self --ucci, I got error following:

2018-11-03 13:21:48.626280: I tensorflow/core/common_runtime/gpu/gpu_device.cc:976] DMA: 0 
2018-11-03 13:21:48.626285: I tensorflow/core/common_runtime/gpu/gpu_device.cc:986] 0:   Y 
2018-11-03 13:21:48.626291: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1045] Creating TensorFlow device (/gpu:0) -> (device: 0, name: GeForce GTX 1080, pci bus id: 0000:01:00.0)
2018-11-03 13:21:48,627@cchess_alphazero.agent.model DEBUG # loading model from /media/yaoxingliu/Project/DeepLearning/ChineseChess-AlphaZero/data/model/model_best_config.json
2018-11-03 13:21:49,913@cchess_alphazero.agent.model DEBUG # loaded model digest = b14704b8970f4b178deb5cac44d7ca16c75f2dbb267d88b856a8d22d7c9fc96b
2018-11-03 13:21:49,927@cchess_alphazero.worker.play_with_ucci_engine DEBUG # Initialize selfplay worker
2018-11-03 13:21:49,935@cchess_alphazero.worker.play_with_ucci_engine DEBUG # Selfplay#Start Process index = 0, pid = 11499
2018-11-03 13:21:49,957@cchess_alphazero.agent.api ERROR # EOF error: 
Exception in thread prediction_worker:
Traceback (most recent call last):
  File "/home/yaoxingliu/.conda/envs/CCZero/lib/python3.6/threading.py", line 916, in _bootstrap_inner
    self.run()
  File "/home/yaoxingliu/.conda/envs/CCZero/lib/python3.6/threading.py", line 864, in run
    self._target(*self._args, **self._kwargs)
  File "/media/yaoxingliu/Project/DeepLearning/ChineseChess-AlphaZero/cchess_alphazero/agent/api.py", line 50, in predict_batch_worker
    while pipe.poll():
  File "/home/yaoxingliu/.conda/envs/CCZero/lib/python3.6/multiprocessing/connection.py", line 255, in poll
    self._check_closed()
  File "/home/yaoxingliu/.conda/envs/CCZero/lib/python3.6/multiprocessing/connection.py", line 136, in _check_closed
    raise OSError("handle is closed")
OSError: handle is closed
CharlesLiuyx commented 5 years ago

Partial same with #21

NeymarL commented 5 years ago

If you want to play with it in UCI mode, please run python cchess_alphazero/uci.py. Or if you want to let it self-play, just run python cchess_alphazero/run.py self.

CharlesLiuyx commented 5 years ago

Thanks for reply. I chekc whole file structure. Is there an api to watch GUI self play by AI? Or I need to generate the record first and run it with another tool?

NeymarL commented 5 years ago

Unfortunately, you need to generate the record first and watch it in other tools. However, the training records are not recorded in standard format (such as PGN file), you should transfer it to standard format first. The good news is that the CChessEnv class in environment/env.py actually has the transfer functionality, and there is a script to invoke its api. Just put and run the script in the environment folder (also copy lib/data_helper.py into envrionment).

CharlesLiuyx commented 5 years ago

Got it! Thanks for answer. Close this issue is fine