コード例 #1
0
def predict_by_model_one(data):
    global ready_model
    if ready_model == False:
        ready_model = get_trained_model(model_file)

    image = convert_base64_to_grayscale_array(data["image"])
    return ready_model.predict([image])
コード例 #2
0
ファイル: test.py プロジェクト: Justinette2175/polarbear
from model import get_trained_model

for key in [('share_count', 100), ('comment_count', 50),
            ('reaction_count', 50)]:
    model = get_trained_model(key[0], key[1], is_logistic=False)
    print(key, model.test())
コード例 #3
0
ファイル: serve.py プロジェクト: Justinette2175/polarbear
from bottle import post, run, hook, HTTPError, request, response

from textblob import TextBlob, Blobber
from textblob_fr import PatternTagger, PatternAnalyzer

from model import get_trained_model

viral_model = get_trained_model('share_count', 100, is_logistic=True)
comment_model = get_trained_model('comment_count', 50)
share_model = get_trained_model('share_count', 100)
reaction_model = get_trained_model('reaction_count', 50)


def assert_in(val, err):
    if not val:
        raise HTTPError(status=400, body=err)


def extract_sentiment(phrase):
    tb = Blobber(pos_tagger=PatternTagger(), analyzer=PatternAnalyzer())
    return (tb(phrase).sentiment[0] / 2) + 0.5


@hook('after_request')
def enable_cors():
    """
    You need to add some headers to each request.
    Don't use the wildcard '*' for Access-Control-Allow-Origin in production.
    """
    response.headers['Access-Control-Allow-Origin'] = '*'
    response.headers['Access-Control-Allow-Methods'] = 'POST'
コード例 #4
0
import cv2
from pyzbar.pyzbar import decode
from model import get_trained_model
import os

model = get_trained_model()
if __name__ == '__main__':
    for image in os.listdir('results/'):
        image = cv2.imread(f'results/{image}')
        print(decode(image))
コード例 #5
0
import argparse
parser = argparse.ArgumentParser()
parser.add_argument('envname', type=str)

args = parser.parse_args()
envname = args.envname

with open(os.path.join('expert_data', envname + '.pkl'), 'rb') as f:
    expert_data = pickle.load(f)
# data for behavioural cloning
X = expert_data['observations']
Y = expert_data['actions']

from model import get_trained_model
model, metrics = get_trained_model(X, Y)

print(metrics.history['loss'][-1], metrics.history['val_loss'][-1])

env = gym.make(envname)

num_rollouts = 3
max_steps = 1000
render = True

returns = []

for i in range(num_rollouts):
    obs = env.reset()
    done = False
    totalr = 0