Source code for zea.backend.tensorflow.utils.utils
"""Utility functions for zea tensorflow modules."""importnumpyasnpimporttensorflowastf
[docs]classDotDict(dict):"""dot.notation access to dictionary attributes"""__getattr__=dict.get__setattr__=dict.__setitem____delattr__=dict.__delitem__
[docs]deftf_snapshot(obj)->dict:"""Returns a snapshot of the object parameters as a dictionary of tensors. Returns: dict: The scan parameters as a dictionary of tensors. """EXCEPTIONS=["angles","_angles"]snapshot=DotDict()forkeyindir(obj):ifkey[0]!="_"andkeynotinEXCEPTIONS:value=getattr(obj,key)ifisinstance(value,(np.ndarray,int,float,list)):# if data is of double precision, convert to float32ifisinstance(value,np.ndarray)andvalue.dtype==np.float64:dtype=tf.float32else:dtype=Nonesnapshot[key]=tf.convert_to_tensor(value,dtype=dtype)returnsnapshot