├── README.md ├── sconce ├── __init__.py └── tflearn.py └── setup.py /README.md: -------------------------------------------------------------------------------- 1 | # sconce 2 | 3 | Sconce is a dashboard for monitoring and comparing data in real time. It was built to be an easy way to visualize the training progress of different machine learning models. 4 | 5 | ![](https://i.imgur.com/cb5ExqZ.png) 6 | 7 | ## Installation 8 | 9 | Install with `pip`: 10 | 11 | ``` 12 | pip install sconce 13 | ``` 14 | 15 | ## Usage 16 | 17 | To start, create a sconce Job with a name and (optionally) parameters. Jobs with the same name will be displayed together, so you can see how different parameters affect results. 18 | 19 | ```python 20 | import sconce 21 | 22 | # Create a sconce job with a name and parameters 23 | job = sconce.Job('my-neural-network', { 24 | 'n_layers': 6, 25 | 'hidden_size': 250, 26 | 'learning_rate': 0.001 27 | }) 28 | ``` 29 | 30 | To plot data, call `job.record(x, y)`. Instead of posting every data point, Sconce will average the values and plot them every `plot_every` calls. 31 | 32 | ```python 33 | # Record x, y values 34 | for x in range(1000): 35 | y = train() 36 | job.record(x, y) 37 | ``` 38 | 39 | Then visit http://sconce.prontotype.us/jobs/my-neural-network to view your results in real time. 40 | 41 | ## Configuration 42 | 43 | If you want more or less granularity, change `job.plot_every` and `job.print_every`: 44 | 45 | ```python 46 | job.plot_every = 10 47 | job.print_every = 100 48 | ``` 49 | 50 | ## Private jobs 51 | 52 | **TODO:** Register for an account and API key at http://sconce.prontotype.us/ to create private boards. 53 | 54 | ```python 55 | sconce.login('spro', 'asdf1234uiop5768') 56 | ``` 57 | -------------------------------------------------------------------------------- /sconce/__init__.py: -------------------------------------------------------------------------------- 1 | import requests 2 | import time 3 | import math 4 | import os 5 | import sys 6 | import socket 7 | from multiprocessing import Process 8 | 9 | HOST = 'api.sconce.prontotype.us' 10 | if 'SCONCE_HOST' in os.environ: 11 | HOST = os.environ['SCONCE_HOST'] 12 | 13 | # Helpers 14 | 15 | def time_since(since): 16 | now = time.time() 17 | s = now - since 18 | m = math.floor(s / 60) 19 | s -= m * 60 20 | return '%dm %ds' % (m, s) 21 | 22 | def req(method, path, json): 23 | return requests.request(method, 'http://%s/%s.json' % (HOST, path), json=json) 24 | 25 | # Start a job 26 | 27 | class Job: 28 | def __init__(self, name, params={}, hostname=None): 29 | self.name = name 30 | self.params = params 31 | self.hostname = hostname or socket.gethostname() 32 | 33 | self.start() 34 | 35 | def start(self): 36 | r = req('post', 'jobs', {'name': self.name, 'params': self.params, 'hostname': self.hostname}) 37 | body = r.json() 38 | 39 | if r.status_code != 200: 40 | print("JOB CLAIMED", r.status_code, r.content) 41 | sys.exit() 42 | 43 | self.job_id = body['id'] 44 | print("Starting job %s at %s" % (self.job_id, time.strftime('%Y-%m-%d %H:%M:%S', time.localtime()))) 45 | self.start_time = time.time() 46 | 47 | self.log_every = 50 48 | self.plot_every = 50 49 | self.loss_avg = 0 50 | 51 | def stop(self, ): 52 | req('put', 'jobs/%s' % self.job_id, {'status': 'done'}) 53 | 54 | def log(self, l): 55 | print('[log] %s' % time_since(self.start_time), l) 56 | Process(target=req, args=('post', 'jobs/%s/logs' % self.job_id, {'body': l})).start() 57 | 58 | def plot(self, x, y): 59 | Process(target=req, args=('post', 'jobs/%s/points' % self.job_id, {'x': x, 'y': y})).start() 60 | 61 | def record(self, e, loss): 62 | self.loss_avg += loss 63 | 64 | if e > 0 and e % self.log_every == 0: 65 | self.log('(%s) %.4f' % (e, loss)) 66 | 67 | if e > 0 and e % self.plot_every == 0: 68 | self.plot(e, self.loss_avg / self.plot_every) 69 | self.loss_avg = 0 70 | 71 | -------------------------------------------------------------------------------- /sconce/tflearn.py: -------------------------------------------------------------------------------- 1 | import sconce 2 | import tflearn 3 | 4 | class TflearnJob(tflearn.callbacks.Callback): 5 | def __init__(self, name): 6 | self.job = sconce.Job(name) 7 | 8 | def on_epoch_end(self, training_state): 9 | self.job.record(training_state.step, training_state.loss_value) 10 | 11 | -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | from setuptools import setup 2 | 3 | setup(name='sconce', 4 | version='0.0.2', 5 | description='Sconce graph helper', 6 | url='http://github.com/spro/sconce-python', 7 | author='Sean Robertson', 8 | author_email='sprobertson@gmail.com', 9 | license='MIT', 10 | packages=['sconce'], 11 | zip_safe=False) 12 | 13 | --------------------------------------------------------------------------------