For binary classification, the number of units in the last fully-connected layer can be 1 or 2.

If you use Sigmoid activation, you must apply 1 unit for the las FC layer (Your above code is correct). In this case, the loss function should be BCE.
If you use Softmax activation, you should apply 2 units. In this case, the loss function should be CE.