def __init__(self, h, w, action_shape, device='cpu'):
    super(DQN, self).__init__()
    self.device = device
    self.conv1 = nn.Conv2d(4, 16, kernel_size=5, stride=2)
    self.bn1 = nn.BatchNorm2d(16)
    self.conv2 = nn.Conv2d(16, 32, kernel_size=5, stride=2)
    self.bn2 = nn.BatchNorm2d(32)
    self.conv3 = nn.Conv2d(32, 32, kernel_size=5, stride=2)
    self.bn3 = nn.BatchNorm2d(32)

    def conv2d_size_out(size, kernel_size=5, stride=2):
        return ((((size - (kernel_size - 1)) - 1) // stride) + 1)
    convw = conv2d_size_out(conv2d_size_out(conv2d_size_out(w)))
    convh = conv2d_size_out(conv2d_size_out(conv2d_size_out(h)))
    linear_input_size = ((convw * convh) * 32)
    self.fc = nn.Linear(linear_input_size, 512)
    self.head = nn.Linear(512, action_shape)
def __init__(self, h, w, action_shape, device='cpu'):
    super(DQN, self).__init__()
    self.device = device
    self.conv1 = nn.Conv2d(4, 16, kernel_size=5, stride=2)
    self.bn1 = nn.BatchNorm2d(16)
    self.conv2 = nn.Conv2d(16, 32, kernel_size=5, stride=2)
    self.bn2 = nn.BatchNorm2d(32)
    self.conv3 = nn.Conv2d(32, 32, kernel_size=5, stride=2)
    self.bn3 = nn.BatchNorm2d(32)

    def conv2d_size_out(size, kernel_size=5, stride=2):
        return ((((size - (kernel_size - 1)) - 1) // stride) + 1)
    convw = conv2d_size_out(conv2d_size_out(conv2d_size_out(w)))
    convh = conv2d_size_out(conv2d_size_out(conv2d_size_out(h)))
    linear_input_size = ((convw * convh) * 32)
    self.fc = nn.Linear(linear_input_size, 512)
    self.head = nn.Linear(512, action_shape)