If model is an instance of DetectionNet(), you might just be lucky to with the random number generator in the second approach and might not run into negative values in the sqrt.
How reproducible is the finding? I.e. if you both approaches with different seeds, is the first one always failing while the latter is successful?