Ejemplo n.º 1
0
def prepare():
    global ac
    with gzip.open('engmodel6.json.gz', 'rb') as f:
        countdict = json.load(f,object_pairs_hook=sdict)
    with open("symbols.json") as f:
        symbols = json.load(f)
    ac = ArithmeticCodec(modelbuilder.build_model(countdict,symbols))
Ejemplo n.º 2
0
def prepare():
    global ac
    with gzip.open('engmodel6.json.gz', 'rb') as f:
        countdict = json.load(f, object_pairs_hook=sdict)
    with open("symbols.json") as f:
        symbols = json.load(f)
    ac = ArithmeticCodec(modelbuilder.build_model(countdict, symbols))
Ejemplo n.º 3
0
def main():
    in_arg = utility.get_input_args()
    print(in_arg)
    device = utility.set_device_type(in_arg.gpu)
    image_datasets, dataloaders = utility.load_data(in_arg.data_dir)
    cat_to_name = utility.load_category_map()
    model, criterion, optimizer = modelbuilder.build_model(in_arg, device)

    train_model(model, dataloaders['train'], dataloaders['valid'],
                in_arg.epochs, 40, criterion, optimizer, device)

    modelbuilder.save_model(in_arg, model, image_datasets['train'], optimizer)
Ejemplo n.º 4
0
Gotta make you understand

Never gonna give you up, never gonna let you down
Never gonna run around and desert you
Never gonna make you cry, never gonna say goodbye
Never gonna tell a lie and hurt you"""
    teststring = u"THIS IS A TEST OF ALL CAPS COMPRESSION."
    sys.stdout.write("Loading and compiling english model...");sys.stdout.flush()
    starttime = time.time()
    with gzip.open('engmodel6.json.gz', 'rb') as f:
        countdict = json.load(f,object_pairs_hook=sdict)
    #with gzip.open('engmodel2.json.gz','rb') as f:
    #    teststring = " ".join(json.load(f).keys()[:10000])
    with open("symbols.json") as f:
        symbols = json.load(f)
    fullmodel = modelbuilder.build_model(countdict,symbols)
    print "done: %d seconds"%(time.time()-starttime)
    sys.stdout.write("Creating arithmetic coder based on model...");sys.stdout.flush()
    ac = ArithmeticCodec(fullmodel)
    print "done."
    sys.stdout.write("Encoding test string...");sys.stdout.flush()
    starttime = time.time()
    bq = ac.encode(teststring)
    print "done: %d seconds, length: %d"%(time.time()-starttime, len(bq))
    bq.pushBits("110100100010000")
    #print bq.byteString()
    #print bq.bitString()
    sys.stdout.write("Decoding test bit sequence...");sys.stdout.flush()
    starttime = time.time()
    output = ac.decode(bq)
    print "done: %d seconds"%(time.time()-starttime)
Ejemplo n.º 5
0
Never gonna give you up, never gonna let you down
Never gonna run around and desert you
Never gonna make you cry, never gonna say goodbye
Never gonna tell a lie and hurt you"""
    teststring = u"THIS IS A TEST OF ALL CAPS COMPRESSION."
    sys.stdout.write("Loading and compiling english model...")
    sys.stdout.flush()
    starttime = time.time()
    with gzip.open('engmodel6.json.gz', 'rb') as f:
        countdict = json.load(f, object_pairs_hook=sdict)
    #with gzip.open('engmodel2.json.gz','rb') as f:
    #    teststring = " ".join(json.load(f).keys()[:10000])
    with open("symbols.json") as f:
        symbols = json.load(f)
    fullmodel = modelbuilder.build_model(countdict, symbols)
    print "done: %d seconds" % (time.time() - starttime)
    sys.stdout.write("Creating arithmetic coder based on model...")
    sys.stdout.flush()
    ac = ArithmeticCodec(fullmodel)
    print "done."
    sys.stdout.write("Encoding test string...")
    sys.stdout.flush()
    starttime = time.time()
    bq = ac.encode(teststring)
    print "done: %d seconds, length: %d" % (time.time() - starttime, len(bq))
    bq.pushBits("110100100010000")
    #print bq.byteString()
    #print bq.bitString()
    sys.stdout.write("Decoding test bit sequence...")
    sys.stdout.flush()