def main(unused_argv): global labels print('Saving results to %s' % FLAGS.output_dir) labels, _ = input.load_labels() engines = init_engines(3) #_process_dataset('validation', FLAGS.validation_dir, engines) _process_dataset('train', FLAGS.train_dir, engines)
import tensorflow as tf import numpy as np import chess import model import input FLAGS = tf.app.flags.FLAGS label_strings, _ = input.load_labels() with tf.device('/cpu:0'): board = tf.placeholder(tf.float32, shape=[1, 8, 8, 6]) turn = tf.placeholder(tf.float32, shape=[1]) #player = tf.placeholder(tf.float32, shape=[1]) label = tf.placeholder(tf.int64, shape=[1]) example = [board, turn] features, _ = model.feature_extractor([board]) logits, _ = model.model(example, features) onehot_labels = tf.one_hot(label, model.NUM_LABELS, dtype=tf.float32) loss = tf.reduce_mean( tf.nn.softmax_cross_entropy_with_logits(logits=logits, labels=onehot_labels)) saver = tf.train.Saver() config = tf.ConfigProto() config.gpu_options.allow_growth = True sess = tf.Session(config=config) checkpoint = tf.train.get_checkpoint_state(FLAGS.logdir)
if op.name.find("Relu") != -1: tensor_to_vis = tf.get_default_graph().get_tensor_by_name(op.name + ":0") if len(tensor_to_vis.shape) == 4: print(op.name) units = sess.run(tensor_to_vis, feed_dict=feed_dict) filters = units.shape[3] plt.figure(1, figsize=(40,40)) n_columns = 16 n_rows = math.ceil(filters / n_columns) + 1 for i in range(filters): plt.subplot(n_rows, n_columns, i+1) plt.imshow(units[0,:,:,i], interpolation="nearest", cmap="gray") plt.savefig(op.name + ".png") plt.clf() label_strings, switch_indexer = input.load_labels() def main(unused_argv): pass #preds, result_pred = predict("r4r1R/pb2bkp1/4p3/3p1p1q/1ppPnB2/2P1P3/PPQ2PP1/2K4R w - - 0 22") #preds, result_pred = predict("r4r1R/pb2bkp1/4p3/3p1p1R/1ppPnB2/2P1P3/PPQ2PP1/2K5 b - - 0 22") #result_pred = predict_result(chess.Board("r1bqkbB1/2ppn1p1/ppP2p1p/4p3/4P3/2N2N2/PPP2PPP/R1BQK2R b KQq - 0 9")) #print("Result:", result_pred) #visualize_layer(chess.Board("r1bqkbB1/2ppn1p1/ppP2p1p/4p3/4P3/2N2N2/PPP2PPP/R1BQK2R b KQq - 0 9")) preds = predict_move("rnbqkbnr/ppppp1pp/5p2/8/4P3/8/PPPP1PPP/RNBQKBNR w KQkq - 0 2") print(preds) # argmax = np.argmax(preds, 0) # print("Best: " + label_strings[argmax] + " " + str(preds[argmax])) # candidates = np.argpartition(preds, -20)[-20:] # candidates = candidates[np.argsort(-preds[candidates])]