Пример #1
0
    def __init__(self, block, layer_num, num_classes=100):
        super(ResNet, self).__init__()

        self.conv1 = conv7x7(3, 64, stride=2, padding=3)

        self.bn1 = bn_with_initialize(64)
        self.relu = P.ReLU()
        self.maxpool = MaxPool2d(kernel_size=3, stride=2, pad_mode="same")

        self.layer1 = MakeLayer0(block,
                                 layer_num[0],
                                 in_channels=64,
                                 out_channels=256,
                                 stride=1)
        self.layer2 = MakeLayer1(block,
                                 layer_num[1],
                                 in_channels=256,
                                 out_channels=512,
                                 stride=2)
        self.layer3 = MakeLayer2(block,
                                 layer_num[2],
                                 in_channels=512,
                                 out_channels=1024,
                                 stride=2)
        self.layer4 = MakeLayer3(block,
                                 layer_num[3],
                                 in_channels=1024,
                                 out_channels=2048,
                                 stride=2)

        self.pool = nn.AvgPool2d(7, 1)
        self.fc = fc_with_initialize(512 * block.expansion, num_classes)
        self.flatten = Flatten()
 def __init__(self, block, num_classes=100):
     super(ResNetModelParallel, self).__init__()
     self.relu = P.ReLU().shard(((1, dev_num, 1, 1),))
     self.maxpool = MaxPool2d(kernel_size=3, stride=2, pad_mode="same")
     self.layer1 = MakeLayer0(
         block, in_channels=64, out_channels=256, stride=1)
     self.pool = M.ReduceMean(keep_dims=True).shard(strategy_no_weight)
     self.fc = fc_with_initialize(64 * block.expansion, num_classes)
     self.flatten = Flatten()
 def __init__(self, num_classes=100):
     super(ResNet, self).__init__()
     strategy_no_weight = ((dev_num, 1, 1, 1),)
     self.conv1 = conv7x7(3, 64, stride=2, padding=0)
     self.bn1 = bn_with_initialize(64)
     self.relu = ReLU()
     self.relu.relu.shard(strategy_no_weight)
     self.maxpool = MaxPool2d(kernel_size=3, stride=2, pad_mode="same")
     self.reshape = P.Reshape()
     self.matmul = P.MatMul().shard(((8, 1), (1, 1)))
     self.matmul_weight = Parameter(Tensor(np.ones([200704, num_classes]), dtype=ms.float32), name="weight")
Пример #4
0
 def __init__(self, block, num_classes=100):
     super(ResNet, self).__init__()
     self.conv1 = conv7x7(3, 64, stride=2)
     self.bn1 = bn_with_initialize(64)
     self.relu = P.ReLU().set_strategy(strategy_no_weight)
     self.maxpool = MaxPool2d(kernel_size=3, stride=2, pad_mode="same")
     self.layer1 = MakeLayer0(block,
                              in_channels=64,
                              out_channels=256,
                              stride=1)
     self.pool = M.ReduceMean(
         keep_dims=True).set_strategy(strategy_no_weight)
     self.fc = fc_with_initialize(64 * block.expansion, num_classes)
     self.flatten = Flatten()