## main/tests ------------------------------------------------------------------ if __name__ == "__main__": import config import usps import time builder = NetworkBuilder(config.test_net) htm = builder.build() htm.start() t0 = time.time() ## train layer 0 image = usps.read("data_sets/train100/0/1.bmp") htm.expose(image) htm.layers[0].train({'temporal_gap' : False}) htm.layers[0].train({'temporal_gap' : False}) image = usps.read("data_sets/train100/0/2.bmp") htm.expose(image) htm.layers[0].train({'temporal_gap' : False}) image = usps.read("data_sets/train100/0/3.bmp") htm.expose(image) htm.layers[0].train({'temporal_gap' : False}) htm.layers[0].finalize() ## train layer 1
print "*** HTM Testing ***" print "1. Test HTM on single input" print "2. Test HTM on USPS train100 training set" print "3. Test HTM on USPS train1000 training set" print "4. Test HTM on USPS full test set (over 2000 elements)" print "5. Quit" choice = int(raw_input()) t0 = time.time() print print "*** Testing HTM ***" if choice == 1: print htm.inference(read('data_sets/test/0/1.bmp')) # import profile # profile.runctx("htm.inference(read('data_sets/test/0/1.bmp'))", globals(), # {'htm': htm, # 'read' : read}) print "Completed in ", time.time() - t0, "seconds" elif choice == 2 or choice == 3 or choice == 4: if choice == 2: directory = USPS_TRAIN100_SET elif choice == 3: directory = USPS_TRAIN1000_SET elif choice == 4: directory = USPS_TEST_SET classes = os.listdir(directory) total = 0 correct = 0