Example #1
0
def get_fitness_gc(dna, kernel, train_set_num=500, test_set_num=1000):
    # Get Data
    mnist = data_reader.read_data_sets("./scripts/data")
    # Change net kernels
    converter = CnnConverter(
        param_file_path="./config/converter_config_default.json")
    converter.ac_kernel(kernel)
    # Create net
    net = CnnNetwork(converter)
    net.create_inputlayer(converter.pro_width * converter.pro_height *
                          converter.kernels_num)
    net.create_outputlayer(10)
    net.link_inputlayer_outputlayer()
    # train
    net.train_all(mnist.train.data[:train_set_num],
                  mnist.train.target[:train_set_num],
                  iter_max=2,
                  accuracy_rate=.95)
    # predict
    accuracy = net.predict_all(mnist.test.data[:test_set_num],
                               mnist.test.target[:test_set_num],
                               is_record_error_msg=False)
    # log result
    if net.synchronizer.rank == 0:
        print("{ DNA: ", dna, ",accuracy: ", accuracy, "}")

    del net
    return accuracy
Example #2
0
def get_fitness(net, kernels, test_set_num=1000):
    # Get Data
    mnist = data_reader.read_data_sets("./scripts/data")
    # Change net kernels
    net.converter.change_kernal(kernels)
    # predict
    accuracy = net.predict_all(mnist.test.data[:test_set_num],
                               mnist.test.target[:test_set_num])
    return accuracy
Example #3
0

def read_result(path):
    re_scv = np.loadtxt(path, dtype=np.int)
    return re_scv


if __name__ == "__main__":

    disconnect_w = 1.  # adjust parameter

    training_set_num = 1000
    testing_set_num = 10000
    classifier_num = 1

    mnist = data_reader.read_data_sets("./scripts/data")

    # 参数 转换函数,图片的宽高
    converter = CnnConverter(
        param_file_path="./config/converter_config_default.json")
    # 设置teacher信号的位置
    converter.teacher = 75.
    print(converter.pro_width)
    print(converter.pro_height)

    is_fail = False
    all_result = []
    rest_synapse = []

    # train
    for _ in range(classifier_num):
Example #4
0
                    intermediate_result[key] = self.convolution_layer(intermediate_result[key], kernal=self.kernels[key])
            elif op == 'pooling':
                for key in self.kernels.keys():
                    intermediate_result[key] = self.max_pooling_layer(intermediate_result[key])

        return intermediate_result

    @staticmethod
    def draw_data(ori_image, new_image=221):
        plt.subplot(new_image)
        plt.imshow(ori_image)


# Unit Test
if __name__ == "__main__":
    mnist = data_read.read_data_sets("../../scripts/data")
    converter = CnnConverter(param_file_path='../../config/converter_config_default.json')

    image = mnist.train.data[1]
    print("Target %s" % mnist.train.target[1])
    print(converter.pro_width, converter.pro_height)

    pre = converter.pre_pro_c(image)
    num = 1
    for value in pre.values():
        converter.draw_data(value, 220 + num)
        num += 1
        if num > 4:
            num = 1
            plt.figure()