def testInconvertibleTensorProto(self): self.assertFalse(debug_data.has_inf_or_nan( self._dummy_datum, debug_data.InconvertibleTensorProto(tensor_pb2.TensorProto(), initialized=False))) self.assertFalse(debug_data.has_inf_or_nan( self._dummy_datum, debug_data.InconvertibleTensorProto(tensor_pb2.TensorProto(), initialized=True)))
def testFormatResourceTypeTensor(self): tensor_proto = tensor_pb2.TensorProto( dtype=types_pb2.DataType.Value("DT_RESOURCE"), tensor_shape=tensor_shape_pb2.TensorShapeProto( dim=[tensor_shape_pb2.TensorShapeProto.Dim(size=1)])) out = tensor_format.format_tensor( debug_data.InconvertibleTensorProto(tensor_proto), "a") self.assertEqual(["Tensor \"a\":", ""], out.lines[:2]) self.assertEqual(str(tensor_proto).split("\n"), out.lines[2:])
def testFormatUninitializedTensor(self): tensor_proto = tensor_pb2.TensorProto( dtype=types_pb2.DataType.Value("DT_FLOAT"), tensor_shape=tensor_shape_pb2.TensorShapeProto( dim=[tensor_shape_pb2.TensorShapeProto.Dim(size=1)])) out = tensor_format.format_tensor( debug_data.InconvertibleTensorProto(tensor_proto, False), "a") self.assertEqual(["Tensor \"a\":", "", "Uninitialized tensor:"], out.lines[:3]) self.assertEqual(str(tensor_proto).split("\n"), out.lines[3:])
def testAddAndQueryUnitializedTensor(self): watch_key = "Dense/Bias:0:DebugIdentity" watch_store = tensor_store._WatchStore(watch_key, mem_bytes_limit=50) uninitialized_value = debug_data.InconvertibleTensorProto( None, initialized=False) watch_store.add(uninitialized_value) initialized_value = np.zeros([3], dtype=np.float64) watch_store.add(initialized_value) result = watch_store.query([0, 1]) self.assertEqual(2, len(result)) self.assertIsInstance(result[0], debug_data.InconvertibleTensorProto) self.assertAllClose(initialized_value, result[1])
def testLocateTensorElementAnnotationsUnavailable(self): tensor_proto = tensor_pb2.TensorProto( dtype=types_pb2.DataType.Value("DT_FLOAT"), tensor_shape=tensor_shape_pb2.TensorShapeProto( dim=[tensor_shape_pb2.TensorShapeProto.Dim(size=1)])) out = tensor_format.format_tensor( debug_data.InconvertibleTensorProto(tensor_proto, False), "a") self.assertEqual(["Tensor \"a\":", "", "Uninitialized tensor:"], out.lines[:3]) with self.assertRaisesRegexp( AttributeError, "tensor_metadata is not available in annotations"): tensor_format.locate_tensor_element(out, [0])