Exemplo n.º 1
0
async def train(ctx, filename: str, memsize: int):
    try:
        with open("training_data/" + filename + ".txt", "r") as f:
            tdata = f.read()
    except IOError:
        await ctx.send("Error - Specified model does not exist.")
        return

    model = ai.train(tdata, memsize)

    with open("models/" + filename + "-" + str(memsize) + ".model", "w") as f:
        f.write(json.dumps([model, tdata]))

    await ctx.send("Done!")
Exemplo n.º 2
0
    parser_train = subparsers.add_parser(
        'train',
        help=
        'trains the system to detect traffic lights in an image given training samples'
    )

    # command: predict; for predicting traffic lights given an input image
    parser_predict = subparsers.add_parser(
        'predict', help='attempts to find all traffic lights in an image')
    parser_predict.add_argument('--path', help='path to image', required=True)

    # command: mine; for mining positive and negative examples from a given input image
    parser_mine = subparsers.add_parser(
        'mine',
        help='tool for hard mining positive and negative training data')
    parser_mine.add_argument('--path', help='path to image', required=True)
    parser_mine.add_argument(
        '--use-predicted',
        help=
        'whether or not to use the boxes that were predicted as positive samples',
        action='store_true')

    args = parser.parse_args()

    if args.subcmd == 'train':
        ai.train()
    elif args.subcmd == 'predict':
        ai.predict(path.expanduser(args.path))
    elif args.subcmd == 'mine':
        ai.mine(path.expanduser(args.path), args.use_predicted)
Exemplo n.º 3
0
                cTile = tileController.getTile( index )
                index += 1
                nTile = tileController.getTile( index )
                viewController.setTile( cTile, nTile )
    viewController.updateEverything( )
"""

for j in range(5):
    times = 0
    index = 0
    ai.totalReward = 0
    for i in range(10000):
        if timeController.timeEvent():
            if viewController.aiState:
                #move, rotate, rating =  ai.makeMove( cTile )
                ai.train(cTile)
            if not cTile.incY():
                cTile.apply()

                if not gridController.checkForGameOver():
                    scoreController.tileReleased()
                    cTile = nTile
                    index += 1
                    nTile = tileController.getTile(index)
                    viewController.setTile(cTile, nTile)
                else:
                    times += 1
                    cTile = tileController.getTile(index)
                    index += 1
                    nTile = tileController.getTile(index)
                    viewController.setTile(cTile, nTile)
Exemplo n.º 4
0
        val = arg.split("=")[1]
        if data.get(key) != None:
            data[key] = val
        else:
            usage()
    else:
        usage()

if sys.argv[1] == "train":
    if data["training-file"] == "stdin":
        tdata = input()
    else:
        with open(data["training-file"], "r") as f:
            tdata = f.read()

    model = ai.train(tdata, int(data["max-history"]))
    if data["model-file"] == "stdout":
        print(json.dumps(model))
    else:
        with open(data["model-file"], "w") as f:
            f.write(json.dumps([model, tdata]))

elif sys.argv[1] == "predict":
    if data["model-file"] == "stdin":
        model = input()
    else:
        with open(data["model-file"], "r") as f:
            model = json.loads(f.read())[0]

    size = 8
Exemplo n.º 5
0
from io import BytesIO
from PIL import Image
import numpy as np
import requests
import ai

ai_ = None
flag = True

while True:
    url = 'http://0.0.0.0:5000/image/verification'
    res = requests.get(url)
    image = Image.open(BytesIO(res.content))
    image.show()
    length, width = image.size

    if flag:
        user = input('your chose:\n')

    if user == 'ai':
        url = 'http://0.0.0.0:5000/ai/{}'.format(ai_)
        flag = False
        res = requests.get(url)
        print(res.text)
    else:
        check_list = [[int(temp) for temp in user]]
        input_data = np.array(image)
        np.reshape(input_data, (length, width, 3))
        print(check_list)
        ai_ = ai.train(length, width, [input_data], check_list)
        print(ai_)