Ejemplo n.º 1
0
		用于 for loop, just like range() function
		'''
        if len(samples) != len(labels):
            raise Exception('Length of samples and labels must equal')
        stepStart = 0  # initial step
        i = 0
        while stepStart < len(samples):
            stepEnd = stepStart + chunkSize
            if stepEnd < len(samples):
                yield i, samples[stepStart:stepEnd], labels[stepStart:stepEnd]
                i += 1
            stepStart = stepEnd

    net = Network(train_batch_size=128,
                  test_batch_size=100,
                  pooling_scale=2,
                  dropout_rate=0.90,
                  base_learning_rate=0.008,
                  decay_rate=0.99)
    net.define_inputs(
        train_samples_shape=(128, 48, 48, 1),
        train_labels_shape=(128, 7),
        test_samples_shape=(100, 48, 48, 1),
    )
    #
    net.add_conv(patch_size=3,
                 in_depth=1,
                 out_depth=32,
                 activation='relu',
                 pooling=True,
                 name='conv1')
    net.add_conv(patch_size=3,
Ejemplo n.º 2
0
Archivo: main.py Proyecto: oywc410/MYPG
		Iterator/Generator: get a batch of data
		这个函数是一个迭代器/生成器,用于每一次只得到 chunkSize 这么多的数据
		用于 for loop, just like range() function
		'''
        if len(samples) != len(labels):
            raise Exception('Length of samples and labels must equal')
        stepStart = 0  # initial step
        i = 0
        while stepStart < len(samples):
            stepEnd = stepStart + chunkSize
            if stepEnd < len(samples):
                yield i, samples[stepStart:stepEnd], labels[stepStart:stepEnd]
                i += 1
            stepStart = stepEnd

    net = Network(train_batch_size=64, test_batch_size=500, pooling_scale=2)
    net.define_inputs(train_samples_shape=(64, image_size, image_size,
                                           num_channels),
                      train_labels_shape=(64, num_labels),
                      test_samples_shape=(500, image_size, image_size,
                                          num_channels))
    #
    net.add_conv(patch_size=3,
                 in_depth=num_channels,
                 out_depth=16,
                 activation='relu',
                 pooling=False,
                 name='conv1')
    net.add_conv(patch_size=3,
                 in_depth=16,
                 out_depth=16,
        用于 for loop, just like range() function
        """
        if len(samples) != len(labels):
            raise Exception('Length of samples and labels must equal')
        stepStart = 0  # initial step
        i = 0
        while stepStart < len(samples):
            stepEnd = stepStart + chunkSize
            if stepEnd < len(samples):
                yield i, samples[stepStart:stepEnd], labels[stepStart:stepEnd]
                i += 1
            stepStart = stepEnd


    net = Network(
        train_batch_size=64, test_batch_size=500, pooling_scale=2,
        dropout_rate=0.9,
        base_learning_rate=0.001, decay_rate=0.99)
    net.define_inputs(
        train_samples_shape=(64, image_size, image_size, num_channels),
        train_labels_shape=(64, num_labels),
        test_samples_shape=(500, image_size, image_size, num_channels),
    )
    #
    net.add_conv(patch_size=3, in_depth=num_channels, out_depth=32, activation='relu', pooling=False, name='conv1')
    net.add_conv(patch_size=3, in_depth=32, out_depth=32, activation='relu', pooling=True, name='conv2')
    net.add_conv(patch_size=3, in_depth=32, out_depth=32, activation='relu', pooling=False, name='conv3')
    net.add_conv(patch_size=3, in_depth=32, out_depth=32, activation='relu', pooling=True, name='conv4')

    # 4 = 两次 pooling, 每一次缩小为 1/2
    # 32 = conv4 out_depth
    net.add_fc(in_num_nodes=(image_size // 4) * (image_size // 4) * 32, out_num_nodes=128, activation='relu',
Ejemplo n.º 4
0
        用于 for loop, just like range() function
        """
        if len(samples) != len(labels):
            raise Exception('Length of samples and labels must equal')
        stepStart = 0  # initial step
        i = 0
        while stepStart < len(samples):
            stepEnd = stepStart + chunkSize
            if stepEnd < len(samples):
                yield i, samples[stepStart:stepEnd], labels[stepStart:stepEnd]
                i += 1
            stepStart = stepEnd

    net = Network(train_batch_size=64,
                  test_batch_size=500,
                  pooling_scale=2,
                  dropout_rate=0.9,
                  base_learning_rate=0.001,
                  decay_rate=0.99)
    net.define_inputs(
        train_samples_shape=(64, image_size, image_size, num_channels),
        train_labels_shape=(64, num_labels),
        test_samples_shape=(500, image_size, image_size, num_channels),
    )
    #
    net.add_conv(patch_size=3,
                 in_depth=num_channels,
                 out_depth=32,
                 activation='relu',
                 pooling=False,
                 name='conv1')
    net.add_conv(patch_size=3,
        这个函数是一个迭代器/生成器,用于每一次只得到 chunk_size 这么多的数据
        用于 for loop, just like range() function
        """
        if len(samples) != len(labels):
            raise Exception('Length of samples and labels must equal')
        step_start = 0  # initial step
        i = 0
        while step_start < len(samples):
            step_end = step_start + chunk_size
            if step_end < len(samples):
                yield i, samples[step_start:step_end], labels[step_start:step_end]
                i += 1
            step_start = step_end

    print('num:', image_size, num_channels, num_channels)
    net = Network(train_batch_size=64, test_batch_size=500, pooling_scale=2)
    net.define_inputs(
        train_samples_shape=(64, image_size, image_size, num_channels),
        train_labels_shape=(64, num_labels),
        test_samples_shape=(500, image_size, image_size, num_channels)
    )
    #
    net.add_conv(patch_size=3, in_depth=num_channels, out_depth=16, activation='relu', pooling=False, name='conv1')
    net.add_conv(patch_size=3, in_depth=16, out_depth=16, activation='relu', pooling=True, name='conv2')
    net.add_conv(patch_size=3, in_depth=16, out_depth=16, activation='relu', pooling=False, name='conv3')
    net.add_conv(patch_size=3, in_depth=16, out_depth=16, activation='relu', pooling=True, name='conv4')

    # 4 = 两次 pooling, 每一次缩小为 1/2
    # 16 = conv4 out_depth
    net.add_fc(in_num_nodes=(image_size // 4) * (image_size // 4) * 16, out_num_nodes=16, activation='relu', name='fc1')
    net.add_fc(in_num_nodes=16, out_num_nodes=10, activation=None, name='fc2')