Esempio n. 1
0
def recognize_pattern(params):
    clean_params(params)
    net_id = params.get('net-id', 'nn')
    pattern = params.get('pattern')
    status = redis.get(redis_key('status', net_id))
    if status == None:
        return {'success': 0, 'message': 'net not trained'}
    elif status != 'train_mnist: trained':
        return {'success': 0, 'message': status}
    else:
        net = loads(redis.get(redis_key('data', net_id)))
        data = np.zeros((784,1),dtype=float)
        for i, v in enumerate(pattern):
            if v != 0:
                data[i][0] = float(v)
        distribution = list(x[0] for x in net.feedforward(data))
        number = np.argmax(distribution)
        return {'success': 1, 'result': number, 'distribution': distribution }
Esempio n. 2
0
def list_nets():
    """Returns a list of all trained nets and the parameters
    they were created with.
    """
    nets = filter(lambda x: x.split('-')[-1] == 'data', redis.keys())
    if nets.__len__() > 0:
        net_ids = (x[:x.rfind('-')] for x in nets)
        nets = dict((key, json.loads(redis.get(redis_key('params', key)))) for key in net_ids)
        return nets
Esempio n. 3
0
 def get_sms_code(self, request):
     sms_code = request.POST.get('key')
     user_sms_code = redis.get('nedviga_user_sms_{}'.format(self.phone))
     if user_sms_code:
         if int(user_sms_code) == int(sms_code):
             if not User.objects.filter(phone=self.phone):
                 self.user = User()
                 self.user.phone = self.phone
                 self.user.set_password(DEFAULT_PASSWORD)
                 self.user.save()
         else:
             return self.render_internal_error('Invalid sms-code')
     else:
         return self.render_internal_error('Sms-code expired')
Esempio n. 4
0
def train_mnist(params={}):
    """In case network has not been trained a worker
    process will be started and success is returned.
    Success in that situation does not mean the net could
    be trained successfully, this currently cannot be checked.
    The net has finished training as soon as the <net-id>-data
    entry has been made and it shows up in list-nets.
    :params['net-id']: default 'nn'
    :params['epochs']: default 1
    :params['mini-batch-size']: default 4
    :params['lmbda']: 0.0001
    :params['eta']: 0.1
    :params['layers']: [15]
    """
    clean_params(params)
    if 'net-id' not in params.keys():
        params['net-id']='nn'
    r_key = redis_key('status', params['net-id'])
    if redis.exists(r_key):
        return {'success': 0, 'message': redis.get(r_key)}
    else:
	Process(target=train_mnist_worker, args=(params,)).start()
        return {'success': 1}