def testStaticNonPositivePatchSizeRaisesError(self, patch_size):
     image_shape = [6, 7]
     with self.assertRaises(tf.errors.InvalidArgumentError):
         patch_ops.get_patch_mask(0,
                                  0,
                                  patch_size=patch_size,
                                  image_shape=image_shape)
 def testStaticCoordinatesOutsideImageRaisesError(self, y, x):
     image_shape = [15, 10]
     with self.assertRaises(tf.errors.InvalidArgumentError):
         patch_ops.get_patch_mask(y,
                                  x,
                                  patch_size=3,
                                  image_shape=image_shape)
 def testHandleImageShapeWithChannels(self):
     image_shape = [15, 10, 3]
     mask = patch_ops.get_patch_mask(10,
                                     5,
                                     patch_size=3,
                                     image_shape=image_shape)
     self.assertListEqual(mask.shape.as_list(), image_shape[:2])
 def testMaskShape(self):
     image_shape = [15, 10]
     mask = patch_ops.get_patch_mask(10,
                                     5,
                                     patch_size=3,
                                     image_shape=image_shape)
     self.assertListEqual(mask.shape.as_list(), image_shape)
示例#5
0
 def testDynamicNonPositivePatchSizeRaisesError(self):
   image_shape = [6, 7]
   patch_size = -1 * tf.random_uniform([], minval=0, maxval=3, dtype=tf.int32)
   mask = patch_ops.get_patch_mask(
       0, 0, patch_size=patch_size, image_shape=image_shape)
   with self.assertRaises(tf.errors.InvalidArgumentError):
     self.evaluate(mask)
示例#6
0
 def testDynamicCoordinatesOutsideImageRaisesError(self):
   image_shape = [15, 10]
   x = tf.random_uniform([], minval=-2, maxval=-1, dtype=tf.int32)
   y = tf.random_uniform([], minval=0, maxval=1, dtype=tf.int32)
   mask = patch_ops.get_patch_mask(
       y, x, patch_size=3, image_shape=image_shape)
   with self.assertRaises(tf.errors.InvalidArgumentError):
     self.evaluate(mask)
示例#7
0
 def graph_fn():
     image_shape = [6, 7]
     patch_size = -1 * tf.random_uniform(
         [], minval=0, maxval=3, dtype=tf.int32)
     mask = patch_ops.get_patch_mask(0,
                                     0,
                                     patch_size=patch_size,
                                     image_shape=image_shape)
     return mask
示例#8
0
 def graph_fn():
     image_shape = [15, 10]
     x = tf.random_uniform([], minval=-2, maxval=-1, dtype=tf.int32)
     y = tf.random_uniform([], minval=0, maxval=1, dtype=tf.int32)
     mask = patch_ops.get_patch_mask(y,
                                     x,
                                     patch_size=3,
                                     image_shape=image_shape)
     return mask
示例#9
0
 def testMaskAreaPartiallyOutsideImage(self):
   image_shape = [6, 7]
   mask = patch_ops.get_patch_mask(5, 6, patch_size=5, image_shape=image_shape)
   expected_mask = np.array([
       [0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 1, 1, 1],
       [0, 0, 0, 0, 1, 1, 1],
       [0, 0, 0, 0, 1, 1, 1],
   ]).reshape(image_shape).astype(bool)
   self.assertAllEqual(mask, expected_mask)
示例#10
0
 def testMaskAreaWithOddPatchSize(self):
   image_shape = [6, 7]
   mask = patch_ops.get_patch_mask(2, 3, patch_size=3, image_shape=image_shape)
   expected_mask = np.array([
       [0, 0, 0, 0, 0, 0, 0],
       [0, 0, 1, 1, 1, 0, 0],
       [0, 0, 1, 1, 1, 0, 0],
       [0, 0, 1, 1, 1, 0, 0],
       [0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 0],
   ]).reshape(image_shape).astype(bool)
   self.assertAllEqual(mask, expected_mask)
 def testMaskDType(self):
     mask = patch_ops.get_patch_mask(2, 3, patch_size=2, image_shape=[6, 7])
     self.assertDTypeEqual(mask, bool)