示例#1
0
    def __init__(self, input_shape, outputs_count, hidden_count=64):
        super(Model, self).__init__()

        self.device = "cpu"

        self.layers = [
            nn.Linear(input_shape[0], hidden_count),
            nn.ReLU(),
            libs_layers.NoisyLinear(hidden_count, hidden_count),
            nn.ReLU(),
            libs_layers.NoisyLinear(hidden_count, outputs_count)
        ]

        torch.nn.init.xavier_uniform_(self.layers[0].weight)
        torch.nn.init.xavier_uniform_(self.layers[2].weight)
        torch.nn.init.xavier_uniform_(self.layers[4].weight)

        self.model = nn.Sequential(*self.layers)
        self.model.to(self.device)

        print(self.model)
    def __init__(self, input_shape, outputs_count, features_count = 256, residual_blocks = 32):
        super(Model, self).__init__()

        self.device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
        
        self.input_shape    = input_shape
        self.outputs_count  = outputs_count 

        input_height    = self.input_shape[1]
        input_width     = self.input_shape[2]
        
        self.layers_features = []

        self.layers_features.append(nn.Conv2d(input_shape[0], features_count, kernel_size=3, stride=1, padding=1))
        self.layers_features.append(libs_layers.SkipInit())
        self.layers_features.append(nn.ReLU())

        for l in range(residual_blocks):
            self.layers_features.append(ResidualBlock(features_count))


        self.layers_value = [
            nn.Conv2d(features_count, 2, kernel_size=1, stride=1, padding=0),
            libs_layers.SkipInit(),
            nn.ReLU(),
            Flatten(),

            nn.Linear(input_height*input_width*2, 256),
            nn.ReLU(),

            nn.Linear(256, 1)
        ]


        self.layers_advantage = [
            nn.Conv2d(features_count, 2, kernel_size=1, stride=1, padding=0),
            libs_layers.SkipInit(),
            nn.ReLU(),
            Flatten(), 

            libs_layers.NoisyLinear(input_height*input_width*2),
            nn.Linear(input_height*input_width*2, self.outputs_count)
        ]


        for i in range(len(self.layers_features)):
            if hasattr(self.layers_features[i], "weight"):
                torch.nn.init.xavier_uniform_(self.layers_features[i].weight)

        for i in range(len(self.layers_value)):
            if hasattr(self.layers_value[i], "weight"):
                torch.nn.init.xavier_uniform_(self.layers_value[i].weight)

        for i in range(len(self.layers_advantage)):
            if hasattr(self.layers_advantage[i], "weight"):
                torch.nn.init.xavier_uniform_(self.layers_advantage[i].weight)


        self.model_features = nn.Sequential(*self.layers_features)
        self.model_features.to(self.device)

        self.model_value = nn.Sequential(*self.layers_value)
        self.model_value.to(self.device)

        self.model_advantage = nn.Sequential(*self.layers_advantage)
        self.model_advantage.to(self.device)

        print(self.model_features)
        print(self.model_value)
        print(self.model_advantage)
        print("\n\n")
示例#3
0
    def __init__(self, input_shape, outputs_count):
        super(Model, self).__init__()

        self.device = torch.device(
            "cuda" if torch.cuda.is_available() else "cpu")

        self.input_shape = input_shape
        self.outputs_count = outputs_count

        input_channels = self.input_shape[0]
        input_height = self.input_shape[1]
        input_width = self.input_shape[2]

        fc_inputs_count = 64 * (input_width // 16) * (input_height // 16)

        self.layers_features = [
            nn.Conv2d(input_channels, 32, kernel_size=3, stride=1, padding=1),
            nn.ReLU(),
            nn.MaxPool2d(kernel_size=2, stride=2, padding=0),
            nn.Conv2d(32, 32, kernel_size=3, stride=1, padding=1),
            nn.ReLU(),
            nn.MaxPool2d(kernel_size=2, stride=2, padding=0),
            nn.Conv2d(32, 64, kernel_size=3, stride=1, padding=1),
            nn.ReLU(),
            nn.MaxPool2d(kernel_size=2, stride=2, padding=0),
            nn.Conv2d(64, 64, kernel_size=3, stride=1, padding=1),
            nn.ReLU(),
            nn.MaxPool2d(kernel_size=2, stride=2, padding=0),
            Flatten()
        ]

        self.layers_value = [
            nn.Linear(fc_inputs_count, 512),
            nn.ReLU(),
            nn.Linear(512, 1)
        ]

        self.layers_advantage = [
            libs_layers.NoisyLinear(fc_inputs_count, 512),
            nn.ReLU(),
            libs_layers.NoisyLinear(512, outputs_count)
        ]

        for i in range(len(self.layers_features)):
            if hasattr(self.layers_features[i], "weight"):
                torch.nn.init.xavier_uniform_(self.layers_features[i].weight)

        for i in range(len(self.layers_value)):
            if hasattr(self.layers_value[i], "weight"):
                torch.nn.init.xavier_uniform_(self.layers_value[i].weight)

        for i in range(len(self.layers_advantage)):
            if hasattr(self.layers_advantage[i], "weight"):
                torch.nn.init.xavier_uniform_(self.layers_advantage[i].weight)

        self.model_features = nn.Sequential(*self.layers_features)
        self.model_features.to(self.device)

        self.model_value = nn.Sequential(*self.layers_value)
        self.model_value.to(self.device)

        self.model_advantage = nn.Sequential(*self.layers_advantage)
        self.model_advantage.to(self.device)

        print(self.model_features)
        print(self.model_value)
        print(self.model_advantage)
示例#4
0
    def __init__(self,
                 input_shape,
                 outputs_count,
                 kernels_count=[32, 32, 64, 64],
                 residual_count=[0, 0, 0, 0]):
        super(Model, self).__init__()

        self.device = torch.device(
            "cuda" if torch.cuda.is_available() else "cpu")

        self.input_shape = input_shape
        self.outputs_count = outputs_count

        input_channels = self.input_shape[0]
        input_height = self.input_shape[1]
        input_width = self.input_shape[2]

        kernels_count_ = [input_channels] + kernels_count

        fc_inputs_count = 64 * (input_width // 16) * (input_height // 16)

        self.layers_features = []

        for k in range(len(kernels_count_) - 1):

            k_in = kernels_count_[k]
            k_out = kernels_count_[k + 1]

            self.layers_features.append(
                nn.Conv2d(k_in, k_out, kernel_size=3, stride=1, padding=1))
            #self.layers_features.append(libs_layers.SkipInit())
            self.layers_features.append(nn.ReLU())

            for i in range(residual_count[k]):
                self.layers_features.append(ResidualBlock(k_out))

            self.layers_features.append(
                nn.MaxPool2d(kernel_size=2, stride=2, padding=0))

        self.layers_features.append(Flatten())

        self.layers_value = [
            nn.Linear(fc_inputs_count, 512),
            nn.ReLU(),
            nn.Linear(512, 1)
        ]

        self.layers_advantage = [
            libs_layers.NoisyLinear(fc_inputs_count, 512),
            nn.ReLU(),
            libs_layers.NoisyLinear(512, outputs_count)
        ]

        for i in range(len(self.layers_features)):
            if hasattr(self.layers_features[i], "weight"):
                torch.nn.init.xavier_uniform_(self.layers_features[i].weight)

        for i in range(len(self.layers_value)):
            if hasattr(self.layers_value[i], "weight"):
                torch.nn.init.xavier_uniform_(self.layers_value[i].weight)

        for i in range(len(self.layers_advantage)):
            if hasattr(self.layers_advantage[i], "weight"):
                torch.nn.init.xavier_uniform_(self.layers_advantage[i].weight)

        self.model_features = nn.Sequential(*self.layers_features)
        self.model_features.to(self.device)

        self.model_value = nn.Sequential(*self.layers_value)
        self.model_value.to(self.device)

        self.model_advantage = nn.Sequential(*self.layers_advantage)
        self.model_advantage.to(self.device)

        print(self.model_features)
        print(self.model_value)
        print(self.model_advantage)