Ok so first off the cnn is output the correct number of channels. The shape of the output is [batch_size, channels, width, height]. So the second number is the channels which is 18 so that is correct. Also is your forward function working because it does not look like it should. You are not flattening the image so you are passing in a four dimensional tensor while linear layers only take two dimensions. Your linear layers also does not have enough inputs to take an image of that size. To flatten the output you can do this
x = x.view(-1, x.shape[1] * x.shape[2] * x.shape[3])

If the output of your cnn is that big that means the input of ln1 should be 432. One last problem is you do not zero out the gradients in your training loop. After you do optimizier.step() you need to do this
optimizer.zero_grad()

Here is the pytorch classification tutorial if you want to look at it for some reference. You also need to change your loss to binary_cross_entropy_with_logits which includes a softmax.