junxiaosong / AlphaZero_Gomoku

An implementation of the AlphaZero algorithm for Gomoku (also called Gobang or Five in a Row)
MIT License
3.27k stars 964 forks source link

No module named 'numpy.core.multiarray\r' #1

Closed initial-h closed 6 years ago

initial-h commented 6 years ago

Traceback (most recent call last): File "human_play.py", line 75, in run() File "human_play.py", line 59, in run policy_param = pickle.load(open('best_policy_8_8_5.model', 'rb')) ImportError: No module named 'numpy.core.multiarray\r'

junxiaosong commented 6 years ago

I google the error and found some clue: https://stackoverflow.com/questions/35359641/python-2-7-pickle-wont-recognize-numpy-multiarray

It seems usually the problem is caused by using different operating systems, and my model files are saved on Windows7. But I just tried to run the code on Linux, and it still works fine for me. And also, the provided model files were saved in binary format by using 'wb' when dumped.

So, maybe it is a problem of the numpy itself, what's the version of numpy you are using?

initial-h commented 6 years ago

my system is win10,and i try it with python3.5,and my numpy is 1.13.3(i have changed cpickle with pickle on 3.5). but just now,i try it on python2.7,it still give me this Traceback (most recent call last): File "human_play.py", line 75, in run() File "human_play.py", line 59, in run policy_param = pickle.load(open('best_policy_8_8_5.model', 'rb')) ImportError: No module named multiarray

and my numpy on 2.7 is 1.11.3.

i also try it on the server ,still the same error

junxiaosong commented 6 years ago

The original models were dumped using pickle with default protocol=0, which may be problematic. I just re-dumped all models using pickle.HIGHEST_PROTOCOL. Now the model size is less than 1/2 of the original ones. You can download the new models to see if it solves your problem.

If the problem persists, maybe I need to save the model parameters using hdf5 format.

initial-h commented 6 years ago

thank u very much, i can load it with my python2.7 now. but with python3.5,another problem come up

Traceback (most recent call last): File "human_play.py", line 75, in run() File "human_play.py", line 59, in run policy_param = pickle.load(open('best_policy_8_8_5.model', 'rb')) UnicodeDecodeError: 'ascii' codec can't decode byte 0x91 in position 0: ordinal not in range(128)

i think it's because the module pickle, it is cPickle in 2.7,but in 3.5 it has beed removed and pickle instead again thank u a lot!

junxiaosong commented 6 years ago

I just modified the code so that we can run human_play.py in python3. For the pickle issue of python3, adding the encoding parameter solves the problem.

pickle.load(open(model_file, 'rb'), encoding = 'bytes')

ShinsukeSakai0321 commented 4 years ago

python assumes the format of input file is made in unix system. In this case, termination of line is expressed only by LF(\n). However, in a file made in windows system, termination of line is expressed by CR+LF(\r\n). Thus you need to convert the input file using nkf command on command prompt as follows. $ nkf -Lu file_windows.txt > file_unix.txt