I suspect that you have some images without Exif (or that Hugo failed to read it for some reason).
I suggest you rewrite it to somthing like this:
{{ with $photo }}
{ { $orientation := 1 }}
{{ with .Exif }}
{{ $orientation = .Tags.Orientation }}
{{ end }}
{{ end }}