def test(expid): # to test: # OMP_NUM_THREADS=1 THEANO_FLAGS=device=cpu taskset -c 0 python $(expip)/code.py $(expid) import os os.chdir(expid) print "loading data" data = GenericClassificationDataset("cifar10", "../cifar_10_shuffled.pkl") print "building model" model, learn, test = build_model(False) print "importing weights" shared.importFromFile("weights.pkl") print "testing" import time t0 = time.time() test_error, test_cost = data.doTest(test, 50) t1 = time.time() print "Error, cost, time(s)" print test_error, test_cost, t1 - t0 specialized_test_time = t1 - t0 normal_test_time = t1 - t0 f = file("test_results.txt", 'w') f.write("specialized:%f\ntheano:%f\nerror:%f\n" % (specialized_test_time, normal_test_time, test_error)) f.close()
def test(expid): # to test: # OMP_NUM_THREADS=1 THEANO_FLAGS=device=cpu taskset -c 0 python $(expip)/code.py $(expid) import os os.chdir(expid) print "loading data" data = GenericClassificationDataset("cifar10", "../cifar_10_shuffled.pkl") print "building model" model,learn,test = build_model(False) print "importing weights" shared.importFromFile("weights.pkl") print "testing" import time t0 = time.time() test_error, test_cost = data.doTest(test, 50) t1 = time.time() print "Error, cost, time(s)" print test_error, test_cost, t1-t0 specialized_test_time = t1-t0 normal_test_time = t1-t0 f= file("test_results.txt",'w') f.write("specialized:%f\ntheano:%f\nerror:%f\n"%(specialized_test_time, normal_test_time, test_error)) f.close()
def main(): data = GenericClassificationDataset("cifar10", "cifar_10_shuffled.pkl") N = data.train[0].shape[0] * 1. model, learn, test = build_model() some_probs = [] epoch = 0 experiment = {"results":None, } lr = 0.001 # * 100 / (i+100) costs = [] errors = [] valid_costs = [] valid_errors = [] for i in range(1000): epoch = i cost = 0 error = 0 for x,y in data.trainMinibatches(128): c,e = learn(x,y,lr) cost += c error += e t0 = time.time() valid_error, valid_cost = data.validate(test, 50) valid_time = time.time() - t0 print print i, cost/N, error/N print valid_error, valid_cost, valid_time errors.append(error/N) costs.append(cost/N) valid_errors.append(valid_error) valid_costs.append(valid_cost) tools.export_feature_image(model.layers[0].h.W, "W_img.png", (32,32,3)) tools.export_multi_plot1d([errors, valid_errors], "errors.png", "error") tools.export_multi_plot1d([costs, valid_costs], "costs.png", "cost") experiment["results"] = [valid_costs, valid_errors, costs, errors] experiment["valid_time"] = valid_time pickle.dump(experiment, file("experiment.pkl",'w'),-1) shared.exportToFile("weights.pkl")
def main(): data = GenericClassificationDataset("cifar10", "cifar_10_shuffled.pkl") N = data.train[0].shape[0] * 1. model, learn, test = build_model() some_probs = [] epoch = 0 experiment = { "results": None, } lr = 0.001 # * 100 / (i+100) costs = [] errors = [] valid_costs = [] valid_errors = [] for i in range(1000): epoch = i cost = 0 error = 0 for x, y in data.trainMinibatches(128): c, e = learn(x, y, lr) cost += c error += e t0 = time.time() valid_error, valid_cost = data.validate(test, 50) valid_time = time.time() - t0 print print i, cost / N, error / N print valid_error, valid_cost, valid_time errors.append(error / N) costs.append(cost / N) valid_errors.append(valid_error) valid_costs.append(valid_cost) tools.export_feature_image(model.layers[0].h.W, "W_img.png", (32, 32, 3)) tools.export_multi_plot1d([errors, valid_errors], "errors.png", "error") tools.export_multi_plot1d([costs, valid_costs], "costs.png", "cost") experiment["results"] = [valid_costs, valid_errors, costs, errors] experiment["valid_time"] = valid_time pickle.dump(experiment, file("experiment.pkl", 'w'), -1) shared.exportToFile("weights.pkl")
def main(): data = GenericClassificationDataset("cifar10", "cifar_10_shuffled.pkl") N = data.train[0].shape[0] * 1. model, learn, test = build_model() do_video = True some_probs = [] fps = 30 try: video = Popen(['avconv', '-y', '-f', 'image2pipe', '-vcodec', 'mjpeg',#'rawvideo', "-pix_fmt", "rgba", '-r', str(fps),'-s','800x600', '-i', '-', '-qscale', '9', '-r', str(fps), 'video.webm'], stdin=PIPE) except Exception,e: print "Cannot do video:",e do_video = False