To select the last epoch, you need to get the index of the epoch loop and then test if the index is indeed the last epoch.
for epoch in range(epochs):
    if epoch == epochs - 1:
        # save your images here