Beispiel #1
0
def build_v1_cortex():
    strengths = 1.0  #0.526315789473684
    v1_strength = strengths * 0.5  #1.0/3.0
    v1_inhib = False
    print "strengths:%.5f" % strengths
    print "v1_strength:%.5f" % v1_strength
    print "v1_inhib:", v1_inhib
    print "--- Building Visual Cortex ---"
    c.start_timer()
    # retina.shape = (12,12)x
    # v1.shape = (14,14)x
    retina = RetinalLayer(12, 12, 'Retina')  #emerg: 12x12
    v1 = c.Layer(14, 14, 'V1')  #,k=0.3) #emerg: 14x14
    c.print_timer("made layers")

    ret_v1_p = RetinaV1PositiveConnection(retina,
                                          v1, (12, 12),
                                          strength=strengths)
    ret_v1_n = RetinaV1NegativeConnection(retina,
                                          v1, (12, 12),
                                          strength=strengths)
    v1_v1 = c.FixedMountainConnection(v1,
                                      v1, (11, 11),
                                      inhib=v1_inhib,
                                      strength=v1_strength)  #emerg: 11x11
    c.print_timer("made connections")

    network = c.Cortex([retina, v1], [ret_v1_p, ret_v1_n, v1_v1],
                       'Visual Cortex')
    network.print_structure()
    network.load_data('../data/v1 tests/weights/')
    return network
Beispiel #2
0
def build_visual_cortex():
	strengths = 1.0
	v1_strength = strengths*0.5
	v1_inhib = False
	print "strengths:%.5f"%strengths
	print "v1_strength:%.5f"%v1_strength
	print "v1_inhib:",v1_inhib
	print "--- Building Visual Cortex ---"
	c.start_timer()
	# retina.shape = (12,12)x
	# v1.shape = (14,14)x
	retina = RetinalLayer(36,36,'Retina') #emerg: 12x12
	v1 = c.Layer(168,168,'V1')#emerg: 14x14
	v4 = c.Layer(24,24,'V4')
	it = c.OutputLayer(10,10,'IT')
	c.print_timer("made layers")
	
	ret_v1_p = RetinaV1PositiveConnection(retina,v1,(12,12),strength=strengths,fixed=True)
	ret_v1_n = RetinaV1NegativeConnection(retina,v1,(12,12),strength=strengths,fixed=True)
	v1_v1 = c.FixedMountainConnection(v1,v1,(7,7),inhib=v1_inhib,strength=v1_strength) #emerg: 11x11
	v1_v4 = c.Connection(v1,v4,(12,12))
	v4_it = c.Connection(v4,it,None)
	it_v4 = c.Connection(it,v4,None)
	c.print_timer("made connections")
	
	network = c.Cortex([retina,v1,v4,it],[ret_v1_p,ret_v1_n,v1_v4,v4_it,it_v4],'Visual Cortex')
	network.print_structure()
	network.load_data()
	return network
Beispiel #3
0
def retina_test():
    network = build_v1_cortex()
    ret = network.get_layer('Retina')
    c.print_timer("built layer")

    start_time = time.time()

    ret_v1_p = network.get_connection('Retina_V1_p')
    ret_v1_n = network.get_connection('Retina_V1_n')
    v1 = network.get_layer('v1')
    c.print_stats('pos wt', ret_v1_p.weights)
    c.print_stats('neg wt', ret_v1_n.weights)
    base_path = '../kyo/'
    for i in range(400):  # go for 129
        if i % 10 == 0:
            val = i
            ret_v1_p.save_image_rel(
                '../data/v1 tests/ret_v1_' + str(val) + '.png', ret_v1_n)
            ret_v1_p.save_as_image('../data/v1 tests/ret_v1_p_' + str(val) +
                                   '.png')
            ret_v1_n.save_as_image('../data/v1 tests/ret_v1_n_' + str(val) +
                                   '.png')
            v1.save_image_for_activations('../data/v1 tests/v1_' + str(val) +
                                          '.png')
            network.print_conn_wt_stats()
        pass_time = time.time()
        listing = os.listdir(base_path)
        cycles = []
        total_wt_change = 0
        for idx, path in enumerate(listing):
            ret.load_image(base_path + path, random=True, detailed=False)
            cycle_cnt, wt_change = network.settle()
            total_wt_change += wt_change
            cycles.append(cycle_cnt)
        if i % 50 == 0:
            network.save_data('../data/v1 tests/weights/')
        print '-- Pass %d: %.3fsec (%.2f cycles each for %d imgs)' % (
            i, time.time() - pass_time, float(sum(cycles)) / len(cycles),
            len(listing))

    print '-- Total elapsed time:%.3fsec' % (time.time() - start_time)
    ret_v1_p.save_image_rel('../data/v1 tests/post_ret_v1.png', ret_v1_n)
    c.print_stats('pos wt', ret_v1_p.weights)
    c.print_stats('neg wt', ret_v1_n.weights)
Beispiel #4
0
def build_visual_cortex():
    strengths = 1.0
    v1_strength = strengths * 0.5
    v1_inhib = False
    print "strengths:%.5f" % strengths
    print "v1_strength:%.5f" % v1_strength
    print "v1_inhib:", v1_inhib
    print "--- Building Visual Cortex ---"
    c.start_timer()
    # retina.shape = (12,12)x
    # v1.shape = (14,14)x
    retina = RetinalLayer(36, 36, 'Retina')  #emerg: 12x12
    v1 = c.Layer(168, 168, 'V1')  #emerg: 14x14
    v4 = c.Layer(24, 24, 'V4')
    it = c.OutputLayer(10, 10, 'IT')
    c.print_timer("made layers")

    ret_v1_p = RetinaV1PositiveConnection(retina,
                                          v1, (12, 12),
                                          strength=strengths,
                                          fixed=True)
    ret_v1_n = RetinaV1NegativeConnection(retina,
                                          v1, (12, 12),
                                          strength=strengths,
                                          fixed=True)
    v1_v1 = c.FixedMountainConnection(v1,
                                      v1, (7, 7),
                                      inhib=v1_inhib,
                                      strength=v1_strength)  #emerg: 11x11
    v1_v4 = c.Connection(v1, v4, (12, 12))
    v4_it = c.Connection(v4, it, None)
    it_v4 = c.Connection(it, v4, None)
    c.print_timer("made connections")

    network = c.Cortex([retina, v1, v4, it],
                       [ret_v1_p, ret_v1_n, v1_v4, v4_it, it_v4],
                       'Visual Cortex')
    network.print_structure()
    network.load_data()
    return network
Beispiel #5
0
def retina_test():
	network = build_v1_cortex()
	ret = network.get_layer('Retina')
	c.print_timer("built layer")
	
	start_time = time.time()
	
	ret_v1_p = network.get_connection('Retina_V1_p')
	ret_v1_n = network.get_connection('Retina_V1_n')
	v1 = network.get_layer('v1')
	c.print_stats('pos wt',ret_v1_p.weights)
	c.print_stats('neg wt',ret_v1_n.weights)
	base_path = '../kyo/'
	for i in range(400): # go for 129
		if i%10 == 0:
			val = i
			ret_v1_p.save_image_rel('../data/v1 tests/ret_v1_'+str(val)+'.png',ret_v1_n)
			ret_v1_p.save_as_image('../data/v1 tests/ret_v1_p_'+str(val)+'.png')
			ret_v1_n.save_as_image('../data/v1 tests/ret_v1_n_'+str(val)+'.png')
			v1.save_image_for_activations('../data/v1 tests/v1_'+str(val)+'.png')
			network.print_conn_wt_stats()
		pass_time = time.time()
		listing = os.listdir(base_path)
		cycles = []
		total_wt_change = 0
		for idx,path in enumerate(listing):
			ret.load_image(base_path + path,random=True,detailed=False)
			cycle_cnt,wt_change = network.settle()
			total_wt_change += wt_change
			cycles.append(cycle_cnt)
		if i%50 == 0:
			network.save_data('../data/v1 tests/weights/')
		print '-- Pass %d: %.3fsec (%.2f cycles each for %d imgs)'%(i,time.time()-pass_time,float(sum(cycles))/len(cycles),len(listing))
				
	print '-- Total elapsed time:%.3fsec'%(time.time() - start_time)
	ret_v1_p.save_image_rel('../data/v1 tests/post_ret_v1.png',ret_v1_n)
	c.print_stats('pos wt',ret_v1_p.weights)
	c.print_stats('neg wt',ret_v1_n.weights)
Beispiel #6
0
def build_v1_cortex():
	strengths = 1.0#0.526315789473684
	v1_strength = strengths*0.5#1.0/3.0
	v1_inhib = False
	print "strengths:%.5f"%strengths
	print "v1_strength:%.5f"%v1_strength
	print "v1_inhib:",v1_inhib
	print "--- Building Visual Cortex ---"
	c.start_timer()
	# retina.shape = (12,12)x
	# v1.shape = (14,14)x
	retina = RetinalLayer(12,12,'Retina') #emerg: 12x12
	v1 = c.Layer(14,14,'V1')#,k=0.3) #emerg: 14x14
	c.print_timer("made layers")
	
	ret_v1_p = RetinaV1PositiveConnection(retina,v1,(12,12),strength=strengths)
	ret_v1_n = RetinaV1NegativeConnection(retina,v1,(12,12),strength=strengths)
	v1_v1 = c.FixedMountainConnection(v1,v1,(11,11),inhib=v1_inhib,strength=v1_strength) #emerg: 11x11
	c.print_timer("made connections")
	
	network = c.Cortex([retina,v1],[ret_v1_p,ret_v1_n,v1_v1],'Visual Cortex')
	network.print_structure()
	network.load_data('../data/v1 tests/weights/')
	return network