当前位置: 首页>>代码示例>>Python>>正文


Python config.NUM_CLASSES属性代码示例

本文整理汇总了Python中config.NUM_CLASSES属性的典型用法代码示例。如果您正苦于以下问题:Python config.NUM_CLASSES属性的具体用法?Python config.NUM_CLASSES怎么用?Python config.NUM_CLASSES使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在config的用法示例。


在下文中一共展示了config.NUM_CLASSES属性的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: import config [as 别名]
# 或者: from config import NUM_CLASSES [as 别名]
def __init__(self, layer_params):
        super(ResNetTypeII, self).__init__()
        self.conv1 = tf.keras.layers.Conv2D(filters=64,
                                            kernel_size=(7, 7),
                                            strides=2,
                                            padding="same")
        self.bn1 = tf.keras.layers.BatchNormalization()
        self.pool1 = tf.keras.layers.MaxPool2D(pool_size=(3, 3),
                                               strides=2,
                                               padding="same")

        self.layer1 = make_bottleneck_layer(filter_num=64,
                                            blocks=layer_params[0])
        self.layer2 = make_bottleneck_layer(filter_num=128,
                                            blocks=layer_params[1],
                                            stride=2)
        self.layer3 = make_bottleneck_layer(filter_num=256,
                                            blocks=layer_params[2],
                                            stride=2)
        self.layer4 = make_bottleneck_layer(filter_num=512,
                                            blocks=layer_params[3],
                                            stride=2)

        self.avgpool = tf.keras.layers.GlobalAveragePooling2D()
        self.fc = tf.keras.layers.Dense(units=NUM_CLASSES, activation=tf.keras.activations.softmax) 
开发者ID:calmisential,项目名称:TensorFlow2.0_ResNet,代码行数:27,代码来源:resnet.py

示例2: processor

# 需要导入模块: import config [as 别名]
# 或者: from config import NUM_CLASSES [as 别名]
def processor(sample):
    data, labels, training = sample

    data = utils.augmentation(data.unsqueeze(1).float() / 255.0)
    labels = torch.eye(config.NUM_CLASSES).index_select(dim=0, index=labels)

    data = Variable(data)
    labels = Variable(labels)
    if torch.cuda.is_available():
        data = data.cuda()
        labels = labels.cuda()

    if training:
        classes, reconstructions = model(data, labels)
    else:
        classes, reconstructions = model(data)

    loss = capsule_loss(data, labels, classes, reconstructions)

    return loss, classes 
开发者ID:leftthomas,项目名称:CapsNet,代码行数:22,代码来源:main.py

示例3: __init__

# 需要导入模块: import config [as 别名]
# 或者: from config import NUM_CLASSES [as 别名]
def __init__(self):
        super(CapsuleNet, self).__init__()

        self.conv1 = nn.Conv2d(in_channels=1, out_channels=256, kernel_size=9, stride=1)
        self.primary_capsules = CapsuleLayer(num_capsules=8, num_route_nodes=-1, in_channels=256, out_channels=32,
                                             kernel_size=9, stride=2)
        self.digit_capsules = CapsuleLayer(num_capsules=config.NUM_CLASSES, num_route_nodes=32 * 6 * 6, in_channels=8,
                                           out_channels=16)

        self.decoder = nn.Sequential(
            nn.Linear(16 * config.NUM_CLASSES, 512),
            nn.ReLU(inplace=True),
            nn.Linear(512, 1024),
            nn.ReLU(inplace=True),
            nn.Linear(1024, 784),
            nn.Sigmoid()
        ) 
开发者ID:leftthomas,项目名称:CapsNet,代码行数:19,代码来源:capsnet.py

示例4: forward

# 需要导入模块: import config [as 别名]
# 或者: from config import NUM_CLASSES [as 别名]
def forward(self, x, y=None):
        x = F.relu(self.conv1(x), inplace=True)
        x = self.primary_capsules(x)
        x = self.digit_capsules(x).squeeze().transpose(0, 1)

        classes = (x ** 2).sum(dim=-1) ** 0.5
        classes = F.softmax(classes, dim=-1)

        if y is None:
            # In all batches, get the most active capsule.
            _, max_length_indices = classes.max(dim=1)
            if torch.cuda.is_available():
                y = Variable(torch.eye(config.NUM_CLASSES)).cuda().index_select(dim=0, index=max_length_indices)
            else:
                y = Variable(torch.eye(config.NUM_CLASSES)).index_select(dim=0, index=max_length_indices)
        reconstructions = self.decoder((x * y[:, :, None]).view(x.size(0), -1))

        return classes, reconstructions 
开发者ID:leftthomas,项目名称:CapsNet,代码行数:20,代码来源:capsnet.py

示例5: __init__

# 需要导入模块: import config [as 别名]
# 或者: from config import NUM_CLASSES [as 别名]
def __init__(self, model_file=PATH_TO_CKPT, label_file=PATH_TO_LABELS):
        logger.info('Loading model from: {}...'.format(model_file))
        detection_graph = tf.Graph()
        graph = tf.Graph()
        with tf.Session(graph=detection_graph):
            # load the graph ===
            # loading a (frozen) TensorFlow model into memory

            with graph.as_default():
                od_graph_def = tf.GraphDef()
                with tf.gfile.GFile(model_file, 'rb') as fid:
                    serialized_graph = fid.read()
                    od_graph_def.ParseFromString(serialized_graph)
                    tf.import_graph_def(od_graph_def, name='')

                # loading a label map
                label_map = label_map_util.load_labelmap(label_file)
                categories = label_map_util.convert_label_map_to_categories(label_map, max_num_classes=NUM_CLASSES,
                                                                            use_display_name=True)
                category_index = label_map_util.create_category_index(categories)

        # set up instance variables
        self.graph = graph
        self.category_index = category_index
        self.categories = categories 
开发者ID:IBM,项目名称:MAX-Object-Detector,代码行数:27,代码来源:model.py

示例6: label_to_array

# 需要导入模块: import config [as 别名]
# 或者: from config import NUM_CLASSES [as 别名]
def label_to_array(label):
    try:
        label_array = np.zeros((25, config.NUM_CLASSES))
        for i in range(len(label)):
            try:
                label_array[i, config.CHAR_VECTOR.index(label[i])] = 1
            except Exception as ex:
                label_array[i, 0] = 1
        return label_array
    except Exception as ex:
        print(label)
        raise ex 
开发者ID:Belval,项目名称:NRTR,代码行数:14,代码来源:utils.py

示例7: __generate_all_train_batches

# 需要导入模块: import config [as 别名]
# 或者: from config import NUM_CLASSES [as 别名]
def __generate_all_train_batches(self):
        train_batches = []
        while not self.current_train_offset + self.batch_size > self.test_offset:
            old_offset = self.current_train_offset

            new_offset = self.current_train_offset + self.batch_size

            self.current_train_offset = new_offset

            raw_batch_x, raw_batch_y, raw_batch_la, raw_batch_la_2 = zip(*self.data[old_offset:new_offset])

            batch_y = np.reshape(
                np.array(raw_batch_y),
                (-1)
            )

            batch_seq_len = np.reshape(
                [len(y) for y in raw_batch_y],
                (-1)
            )

            batch_dt = np.reshape(
                np.array(raw_batch_la),
                (-1, 25, config.NUM_CLASSES)
            )

            batch_dt_2 = np.reshape(
                np.array(raw_batch_la_2),
                (-1, 25)
            )

            batch_x = np.reshape(
                np.array(raw_batch_x),
                (-1, self.max_image_width, 32, 1)
            )

            train_batches.append((batch_y, batch_seq_len, batch_dt, batch_dt_2, batch_x))
        return train_batches 
开发者ID:Belval,项目名称:NRTR,代码行数:40,代码来源:data_manager.py

示例8: __generate_all_test_batches

# 需要导入模块: import config [as 别名]
# 或者: from config import NUM_CLASSES [as 别名]
def __generate_all_test_batches(self):
        test_batches = []
        while not self.current_test_offset + self.batch_size > self.data_len:
            old_offset = self.current_test_offset

            new_offset = self.current_test_offset + self.batch_size

            self.current_test_offset = new_offset

            raw_batch_x, raw_batch_y, raw_batch_la, _ = zip(*self.data[old_offset:new_offset])

            batch_y = np.reshape(
                np.array(raw_batch_y),
                (-1)
            )

            batch_dt = np.zeros(
                np.shape(
                    np.reshape(
                        np.array(raw_batch_la),
                        (-1, 25, config.NUM_CLASSES)
                    )
                )
            )

            batch_x = np.reshape(
                np.array(raw_batch_x),
                (-1, self.max_image_width, 32, 1)
            )

            test_batches.append((batch_y, batch_dt, batch_x))
        return test_batches 
开发者ID:Belval,项目名称:NRTR,代码行数:34,代码来源:data_manager.py


注:本文中的config.NUM_CLASSES属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。