示例#1
0
def create_models(features, layers, units):
    postfix = str(uuid.uuid4())[:8]
    input_name = "input_" + postfix
    output_name = "output_" + postfix

    tf_cpu_x, tf_cpu_y = create_tf_model(features, layers, units, "/cpu:0", input_name, output_name)
    tf_gpu_x, tf_gpu_y = create_tf_model(features, layers, units, "/gpu:0", input_name, output_name)

    tf_sess = tf.Session()
    tf_sess.run(tf.initialize_all_variables())

    td_model = td.Model()
    td_model.add(tf_cpu_y, tf_sess)
    td_x, td_y = td_model.get(input_name, output_name)

    tf_cpu_fn = lambda batch: tf_sess.run(tf_cpu_y, feed_dict={tf_cpu_x: batch})
    tf_gpu_fn = lambda batch: tf_sess.run(tf_gpu_y, feed_dict={tf_gpu_x: batch})
    td_fn     = lambda batch: td_y.eval({td_x: batch})

    return collections.OrderedDict([
        ("tf_cpu", tf_cpu_fn),
        ("tf_gpu", tf_gpu_fn),
        ("td", td_fn)
    ])
# -*- coding: utf-8 -*-

import tensorflow as tf
import tfdeploy as td
import numpy as np

# setup tf graph
sess = tf.Session()
x = tf.placeholder("float", shape=[None, 784], name="input")
W = tf.Variable(tf.truncated_normal([784, 100], stddev=0.05))
b = tf.Variable(tf.zeros([100]))
y = tf.nn.softmax(tf.matmul(x, W) + b, name="output")
sess.run(tf.initialize_all_variables())

# setup td model
model = td.Model()
model.add(y, sess)
inp, outp = model.get("input", "output")

# testing code
batch = np.random.rand(10000, 784)


def test_tf():
    return y.eval(session=sess, feed_dict={x: batch})


def test_td():
    return outp.eval({inp: batch})
示例#3
0
if __name__ == '__main__':
    from Coach import Coach
    from FTGEnv import FTGEnv
    from Utils import *
    from Monitor import *
else:
    model_paths = [
        'BasicBot.pkl',
        '../../../FightingICEver.3.10/data/aiData/BasicBot/BasicBot.pkl'
    ]
    model, s1, q = None, None, None

    for model_path in model_paths:
        if os.path.exists(model_path):
            model = td.Model(model_path)
            s1, q = model.get('State', 'fully_connected_1/BiasAdd:0')
            print("Load weight file: {}".format(model_path))
            break

    if model is None:
        print("Can't find weight file")
        exit(1)

    def function_get_q_values(_state):
        return q.eval({state: _state})

    def act_with_np(state, stop_actions):
        screens, energy = state
        screens = screens.reshape(
            [1, resolution[0], resolution[1], resolution[2]])
示例#4
0
import chess
import tfdeploy as td
import itertools
import copy
from util import *

model = td.Model("model.pkl")
x = model.get("input")
y = model.get("output")

def netPredict(first, second):
	global model
	global x
	global y

	x_1 = bitifyFEN(beautifyFEN(first.fen()))
	x_2 = bitifyFEN(beautifyFEN(second.fen()))
	toEval = [[x_1], [x_2]]
	result = y.eval({x: toEval})

	if result[0][0] > result [0][1]:
		return (first, second)
	else:
		return (second, first)

def alphabeta(node, depth, alpha, beta, maximizingPlayer):
	if depth == 0:
		return node
	if maximizingPlayer:
		v = -1
		for move in node.legal_moves:
示例#5
0
    def __init__(self):
        NUMPY_MODEL = "model/model.pkl"

        self.model = tfd.Model(NUMPY_MODEL)

        self.states_, self.controls_, self.dstates_ = self.model.get("states", "controls")
示例#6
0
 def get_model(self):
     if self.session is None:
         self.init_session()
     td_model = td.Model()
     td_model.add(self.logits, self.session)
     return td_model
示例#7
0
def load_from_pikle():
    # model = pickle.load(open('model.pkl', 'rb'))
    model = td.Model('model.pkl')
    return model