Ejemplo n.º 1
0
  def testBatch(self):
    # Build an arbitrary RGB image
    np.random.seed(7)
    batch_size = 5
    shape = (batch_size, 2, 7, 3)

    for nptype in self.float_types:
      inp = GenerateNumpyRandomRGB(shape).astype(nptype)

      # Convert to HSV and back, as a batch and individually
      with self.test_session() as sess:
        batch0 = array_ops.placeholder(nptype, shape=shape)
        with self.test_scope():
          batch1 = image_ops.rgb_to_hsv(batch0)
          batch2 = image_ops.hsv_to_rgb(batch1)
        split0 = array_ops.unstack(batch0)
        with self.test_scope():
          split1 = list(map(image_ops.rgb_to_hsv, split0))
          split2 = list(map(image_ops.hsv_to_rgb, split1))
        join1 = array_ops.stack(split1)
        join2 = array_ops.stack(split2)
        batch1, batch2, join1, join2 = sess.run([batch1, batch2, join1, join2],
                                                {batch0: inp})

      # Verify that processing batch elements together is the same as separate
      self.assertAllClose(batch1, join1)
      self.assertAllClose(batch2, join2)
      self.assertAllCloseAccordingToType(
          batch2, inp, bfloat16_atol=0.03, half_rtol=0.02)
Ejemplo n.º 2
0
    def testBatch(self):
        # Build an arbitrary RGB image
        np.random.seed(7)
        batch_size = 5
        shape = (batch_size, 2, 7, 3)

        for nptype in self.float_types:
            inp = np.random.rand(*shape).astype(nptype)

            # Convert to HSV and back, as a batch and individually
            with self.test_session() as sess:
                batch0 = array_ops.placeholder(nptype, shape=shape)
                with self.test_scope():
                    batch1 = image_ops.rgb_to_hsv(batch0)
                    batch2 = image_ops.hsv_to_rgb(batch1)
                split0 = array_ops.unstack(batch0)
                with self.test_scope():
                    split1 = list(map(image_ops.rgb_to_hsv, split0))
                    split2 = list(map(image_ops.hsv_to_rgb, split1))
                join1 = array_ops.stack(split1)
                join2 = array_ops.stack(split2)
                batch1, batch2, join1, join2 = sess.run(
                    [batch1, batch2, join1, join2], {batch0: inp})

            # Verify that processing batch elements together is the same as separate
            self.assertAllClose(batch1, join1)
            self.assertAllClose(batch2, join2)
            self.assertAllClose(batch2, inp)
Ejemplo n.º 3
0
 def testRGBToHSVRoundTrip(self):
     data = [0, 5, 13, 54, 135, 226, 37, 8, 234, 90, 255, 1]
     rgb_np = np.array(data, dtype=np.float32).reshape([2, 2, 3]) / 255.
     for use_gpu in [True, False]:
         with self.test_session(use_gpu=use_gpu):
             hsv = image_ops.rgb_to_hsv(rgb_np)
             rgb = image_ops.hsv_to_rgb(hsv)
             rgb_tf = rgb.eval()
     self.assertAllClose(rgb_tf, rgb_np)
Ejemplo n.º 4
0
 def testRGBToHSVRoundTrip(self):
   data = [0, 5, 13, 54, 135, 226, 37, 8, 234, 90, 255, 1]
   rgb_np = np.array(data, dtype=np.float32).reshape([2, 2, 3]) / 255.
   for use_gpu in [True, False]:
     with self.test_session(use_gpu=use_gpu):
       hsv = image_ops.rgb_to_hsv(rgb_np)
       rgb = image_ops.hsv_to_rgb(hsv)
       rgb_tf = rgb.eval()
   self.assertAllClose(rgb_tf, rgb_np)
Ejemplo n.º 5
0
 def testRGBToHSVRoundTrip(self):
   data = [0, 5, 13, 54, 135, 226, 37, 8, 234, 90, 255, 1]
   for nptype in self.float_types:
     rgb_np = np.array(data, dtype=nptype).reshape([2, 2, 3]) / 255.
     with self.test_session():
       placeholder = array_ops.placeholder(nptype)
       with self.test_scope():
         hsv = image_ops.rgb_to_hsv(placeholder)
         rgb = image_ops.hsv_to_rgb(hsv)
       rgb_tf = rgb.eval(feed_dict={placeholder: rgb_np})
     self.assertAllCloseAccordingToType(rgb_tf, rgb_np, bfloat16_atol=0.03)
Ejemplo n.º 6
0
 def testRGBToHSVRoundTrip(self):
     data = [0, 5, 13, 54, 135, 226, 37, 8, 234, 90, 255, 1]
     for nptype in self.float_types:
         rgb_np = np.array(data, dtype=nptype).reshape([2, 2, 3]) / 255.
         with self.test_session():
             placeholder = array_ops.placeholder(nptype)
             with self.test_scope():
                 hsv = image_ops.rgb_to_hsv(placeholder)
                 rgb = image_ops.hsv_to_rgb(hsv)
             rgb_tf = rgb.eval(feed_dict={placeholder: rgb_np})
         self.assertAllClose(rgb_tf, rgb_np)
Ejemplo n.º 7
0
  def testBatch(self):
    # Build an arbitrary RGB image
    np.random.seed(7)
    batch_size = 5
    shape = (batch_size, 2, 7, 3)
    inp = np.random.rand(*shape).astype(np.float32)

    # Convert to HSV and back, as a batch and individually
    with self.test_session() as sess:
      batch0 = constant_op.constant(inp)
      batch1 = image_ops.rgb_to_hsv(batch0)
      batch2 = image_ops.hsv_to_rgb(batch1)
      split0 = array_ops.unpack(batch0)
      split1 = map(image_ops.rgb_to_hsv, split0)
      split2 = map(image_ops.hsv_to_rgb, split1)
      join1 = array_ops.pack(split1)
      join2 = array_ops.pack(split2)
      batch1, batch2, join1, join2 = sess.run([batch1, batch2, join1, join2])

    # Verify that processing batch elements together is the same as separate
    self.assertAllClose(batch1, join1)
    self.assertAllClose(batch2, join2)
    self.assertAllClose(batch2, inp)
Ejemplo n.º 8
0
  def testBatch(self):
    # Build an arbitrary RGB image
    np.random.seed(7)
    batch_size = 5
    shape = (batch_size, 2, 7, 3)
    inp = np.random.rand(*shape).astype(np.float32)

    # Convert to HSV and back, as a batch and individually
    with self.test_session() as sess:
      batch0 = constant_op.constant(inp)
      batch1 = image_ops.rgb_to_hsv(batch0)
      batch2 = image_ops.hsv_to_rgb(batch1)
      split0 = array_ops.unpack(batch0)
      split1 = list(map(image_ops.rgb_to_hsv, split0))
      split2 = list(map(image_ops.hsv_to_rgb, split1))
      join1 = array_ops.pack(split1)
      join2 = array_ops.pack(split2)
      batch1, batch2, join1, join2 = sess.run([batch1, batch2, join1, join2])

    # Verify that processing batch elements together is the same as separate
    self.assertAllClose(batch1, join1)
    self.assertAllClose(batch2, join2)
    self.assertAllClose(batch2, inp)