コード例 #1
0
def plot_api(request):
    from bokeh.plotting import figure
    from bokeh.embed import components

    try:
        project = NN_model.objects.get(user=request.user,
                                       pk=request.GET.get('p'))
        if request.GET.get('realtime') == '1':
            plot_data = []
            with open(op.join(MEDIA_ROOT, project.state_file), 'r') as f:
                info = json.load(f)
            return HttpResponse(json.dumps(info),
                                content_type='application/json')
    except BaseException as e:
        logger.warning(
            'excepttion occured when calling plot API. user:{}, method GET:{}'.
            format(request.user, request.GET))
        return HttpResponse('')
    latest_excution = os.path.join(
        file_path,
        max([f for f in os.listdir(file_path) if re.match(r'\d{6}_\d{6}', f)]),
        'logs')
    script, div = bokeh_plot(latest_excution)

    return HttpResponse(json.dumps({
        "script": script,
        "div": div
    }),
                        content_type="application/json")
コード例 #2
0
def plot_api(request):
    import json
    import pandas as pd
    from bokeh.plotting import figure
    from bokeh.embed import components

    file_path = '/home/plash/demo1/logs/'
    script, div = bokeh_plot(file_path)
    print(script, div)

    logs = {}
    train_log = pd.read_csv(file_path + 'train_log')
    train_log.index = [str(i) for i in train_log.index]
    logs['train'] = train_log.to_dict()
    test_log = pd.read_csv(file_path + 'test_log')
    test_log.index = [str(i) for i in test_log.index]
    logs['test'] = test_log.to_dict()
    train_log = pd.read_csv(file_path + 'train_logfull')
    train_log.index = [str(i) for i in train_log.index]
    logs['train_full'] = train_log.to_dict()
    test_log = pd.read_csv(file_path + 'test_logfull')
    test_log.index = [str(i) for i in test_log.index]
    logs['test_full'] = test_log.to_dict()

    return HttpResponse(json.dumps({
        "script": script,
        "div": div
    }),
                        content_type="application/json")
コード例 #3
0
def results(request):
    context = {}
    if request.method == 'GET':
        print(request.GET)
    if request.GET.get('type') == 'train':
        import json
        with open('/home/plash/petpen/state.json', 'r+') as f:
            info = json.load(f)
            info['status'] = 'loading model'
            f.seek(0)
            json.dump(info, f)
        subprocess.Popen(
            'python', '/home/plash/petpen0.1.py', '-m',
            '/media/disk1/petpen/models/{}'.format(request.user), '-d',
            '/media/disk1/petpen/datasets/{}/{}'.format(
                request.user, request.GET.get('dataset')))
        # os.system('python /home/plash/petpen/git/backend/petpen0.1.py -n mnist -m /home/plash/demo1 -d 1 -w model')
        file_path = '/home/plash/demo1/logs/'
        script, div = bokeh_plot(file_path)
        context = {'plot': script, 'plotDiv': div}
    context["datasets"] = Dataset.objects.filter(user_id=request.user)
    return render(request, 'model/results.html', context)
コード例 #4
0
ファイル: views.py プロジェクト: Knight-X/petpen-node
def plot_api(request):
    import json
    import re
    from bokeh.plotting import figure
    from bokeh.embed import components

    file_path = '/media/disk1/petpen/models/2'
    latest_excution = os.path.join(
        file_path,
        max([f for f in os.listdir(file_path) if re.match(r'\d{6}_\d{6}', f)]),
        'logs')
    script, div = bokeh_plot(latest_excution)
    with open('/home/plash/petpen/state.json', 'r+') as f:
        info = json.load(f)
        info['status'] = 'system idle'
        f.seek(0)
        json.dump(info, f)
        f.truncate()

    return HttpResponse(json.dumps({
        "script": script,
        "div": div
    }),
                        content_type="application/json")