在张量流中,我制作了一个将哈希作为输入的常规网络。作为一个例子,我使用了内置的 python hash()函数(是的,它在每个会话中都改变了盐,但这是一个例子)代码是这样的:
from time import time
st = time()
import tensorflow as tf
print(time() - st)
import numpy as np
import chess
import atexit
from numpy import shape
data = open("data.data", "r").readlines()[:10000]
targets = open("targets.data", "r").readlines()[:10000]
boards_data = []
new_targets = []
for i in data:
boards_data.append(hash(i))
for i in targets:
new_targets.append(float(i))
print(len(new_targets))
print(len(boards_data))
print(np.array(new_targets))
print(np.array(boards_data))
def create_model():
model = tf.keras.models.Sequential()
model.add(tf.keras.layers.Reshape((1,1,1)))
model.add(tf.keras.layers.Dense(1000, activation="tanh"))
model.add(tf.keras.layers.Flatten())
model.add(tf.keras.layers.Dense(1, activation='tanh'))
model.compile(loss="mse", optimizer="adam", metrics=['accuracy'])
return model
model = create_model()
model.fit(np.array(boards_data), np.array(new_targets), epochs=10)
model.predict(np.array(hash("8/6P1/5k1K/6r1/8/8/8/8 b - - 0 83")))
错误在预测中。我在如何修复 Tensorflow 中的“IndexError:列表索引超出范围”中看到了 conv2d 示例 ,但事实并非如此......
和回溯:
Traceback (most recent call last):
File "/Volumes/POOPOO USB/lichess-bot/engines/engine2/nn_evaluation/nn_evaluation2.py", line 36, in <module>
model.predict(np.array(hash("8/6P1/5k1K/6r1/8/8/8/8 b - - 0 83")))
File "/Users/ofek/Library/Python/3.8/lib/python/site-packages/tensorflow/python/keras/engine/training.py", line 130, in _method_wrapper
return method(self, *args, **kwargs)
File "/Users/ofek/Library/Python/3.8/lib/python/site-packages/tensorflow/python/keras/engine/training.py", line 1569, in predict
data_handler = data_adapter.DataHandler(
File "/Users/ofek/Library/Python/3.8/lib/python/site-packages/tensorflow/python/keras/engine/data_adapter.py", line 1105, in __init__
self._adapter = adapter_cls(
至尊宝的传说
相关分类