Example #1
0
def stream(url,images,labels):
	"""generate a stream of messages"""
	w = Wot(url)	
	w.start([ 
		(w.new_channel, []),
		(iterate, [ w, images, labels ])
	])
Example #2
0
from wot import Wot
import numpy as np

def echo(message,meta,headers):
	print("Label: %s" % meta)
	print(np.loads(message))
	

w = Wot("amqp://*****:*****@localhost:5672/wot")
w.start( [ 
	( w.new_channel, []),
	( w.stream_resource, [ "mnist", echo ]) 
])
Example #3
0
from wot import Wot

def spam(w):
	w.eval([ 
		(w.write_resource, [ "python", "dave" ]),
		(spam, [ w ])
	])

w = Wot("amqp://*****:*****@localhost:5672/wot")
w.start([
	(w.new_channel, []),
	(spam, [ w ])
])
Example #4
0
from wot import Wot

def echo(message,headers):
	print("hi %s" % message)
	

w = Wot("amqp://*****:*****@localhost:5672/wot")
w.start( [ 
	( w.new_channel, []),
	( w.stream_resource, [ "python", echo ]) 
])
Example #5
0
from wot import Wot

w = Wot("amqp://*****:*****@localhost:5672/wot")
w.start([
	(w.new_channel, []),
	(w.write_resource, [ "python", "dave" ]),
	(exit, [])
])
def stream(url, images, labels):
    """generate a stream of messages"""
    w = Wot(url)
    w.start([(w.new_channel, []), (iterate, [w, images, labels])])
Example #7
0
init = tf.initialize_all_variables()
sess = tf.Session()
sess.run(init)

iterations = 0

images = []
labels = []

def train(message,meta,headers):
	img = np.loads(message)
	img = img.reshape(1, 28 * 28)
	img = img.astype(np.float32)
	img = np.multiply(img, 1.0 / 255.0)

	label = np.array([np.eye(10)[1*meta]])
	images.append(img[0])
	labels.append(label[0])	
	sess.run(train_step, feed_dict={x: img, y_: label, keep_prob: 0.5 })
	++iterations
	if (iterations % 100) == 0:
		print(sess.run(accuracy, feed_dict={x: images, y_: labels, keep_prob: 1.0}))

w = Wot("amqp://*****:*****@127.0.0.1:5672/wot")
w.start( [ 
	( w.new_channel, []),
	( w.create_binding, [ "mnist", "model2" ]),
	( w.stream_resource, [ "model2", train ]) 
])
Example #8
0
accuracy = tf.reduce_mean(tf.cast(correct_prediction, "float"))

init = tf.initialize_all_variables()
sess = tf.Session()
sess.run(init)

iterations = 0

images = []
labels = []


def train(message, meta, headers):
    img = np.loads(message)
    img = img.reshape(1, 28 * 28)
    img = img.astype(np.float32)
    img = np.multiply(img, 1.0 / 255.0)

    label = np.array([np.eye(10)[1 * meta]])
    images.append(img[0])
    labels.append(label[0])
    sess.run(train_step, feed_dict={x: img, y_: label})
    ++iterations
    if (iterations % 100) == 0:
        print(sess.run(accuracy, feed_dict={x: images, y_: labels}))


w = Wot("amqp://*****:*****@127.0.0.1:5672/wot")
w.start([(w.new_channel, []), (w.create_binding, ["mnist", "model1"]),
         (w.stream_resource, ["model1", train])])