我们从Python开源项目中,提取了以下8个代码示例,用于说明如何使用tensorflow.python.framework.dtypes.uint16()。
def testSyntheticTwoChannelUint16(self): with self.test_session() as sess: # Strip the b channel from an rgb image to get a two-channel image. gray_alpha = _SimpleColorRamp()[:, :, 0:2] image0 = constant_op.constant(gray_alpha, dtype=dtypes.uint16) png0 = image_ops.encode_png(image0, compression=7) image1 = image_ops.decode_png(png0, dtype=dtypes.uint16) png0, image0, image1 = sess.run([png0, image0, image1]) self.assertEqual(2, image0.shape[-1]) self.assertAllEqual(image0, image1) # def testShape(self): # with self.test_session(): # png = constant_op.constant('nonsense') # for channels in 0, 1, 3: # image = image_ops.decode_png(png, channels=channels) # self.assertEqual(image.get_shape().as_list(), # [None, None, channels or None])
def _convert_string_dtype(dtype): """Get the type from a string. Arguments: dtype: A string representation of a type. Returns: The type requested. Raises: ValueError: if `dtype` is not supported. """ if dtype == 'float16': return dtypes_module.float16 if dtype == 'float32': return dtypes_module.float32 elif dtype == 'float64': return dtypes_module.float64 elif dtype == 'int16': return dtypes_module.int16 elif dtype == 'int32': return dtypes_module.int32 elif dtype == 'int64': return dtypes_module.int64 elif dtype == 'uint8': return dtypes_module.int8 elif dtype == 'uint16': return dtypes_module.uint16 else: raise ValueError('Unsupported dtype:', dtype)
def testSyntheticUint16(self): with self.test_session() as sess: # Encode it, then decode it image0 = constant_op.constant(_SimpleColorRamp(), dtype=dtypes.uint16) png0 = image_ops.encode_png(image0, compression=7) image1 = image_ops.decode_png(png0, dtype=dtypes.uint16) png0, image0, image1 = sess.run([png0, image0, image1]) # PNG is lossless self.assertAllEqual(image0, image1) # Smooth ramps compress well, but not too well self.assertGreaterEqual(len(png0), 800) self.assertLessEqual(len(png0), 1500)
def test_decode_example_with_jpeg_encoding_at_16Bit_causes_error(self): image_shape = (2, 3, 3) unused_image, serialized_example = self.generate_image( image_format='jpeg', image_shape=image_shape) with self.assertRaises((TypeError, ValueError)): self.run_decode_example(serialized_example, tfexample_decoder.Image(dtype=dtypes.uint16), image_format='jpeg')
def test_input_uint16(self): data = np.matrix([[1, 2], [3, 4]], dtype=np.uint16) self._assert_dtype(np.uint16, dtypes.uint16, data) self._assert_dtype(np.uint16, dtypes.uint16, self._wrap_dict(data))