def _benchmark_adjust_saturation_in_yiq(self, device, cpu_count): image_shape = [299, 299, 3] burn_iters = 100 benchmark_iters = 1000 config = tf.compat.v1.ConfigProto() tag = device + "_%s" % (cpu_count if cpu_count is not None else "all") if cpu_count is not None: config.inter_op_parallelism_threads = 1 config.intra_op_parallelism_threads = cpu_count with self.cached_session("", graph=tf.Graph(), config=config) as sess: with tf.device(device): inputs = tf.Variable( tf.random.uniform(image_shape, dtype=tf.dtypes.float32) * 255, trainable=False, dtype=tf.dtypes.float32) scale = tf.constant(0.1, dtype=tf.dtypes.float32) outputs = distort_image_ops.adjust_hsv_in_yiq( inputs, 0, scale, 1) run_op = tf.group(outputs) sess.run(tf.compat.v1.global_variables_initializer()) benchmark_values = self.run_op_benchmark( sess, run_op, burn_iters=burn_iters, min_iters=benchmark_iters, name="benchmarkAdjustSaturationInYiq_299_299_3_%s" % (tag)) print( "benchmarkAdjustSaturationInYiq_299_299_3_%s step_time: %.2f us" % (tag, benchmark_values['wall_time'] * 1e6))
def _benchmark_adjust_saturation_in_yiq(self, device, cpu_count): image_shape = [299, 299, 3] warmup_rounds = 100 benchmark_rounds = 1000 config = tf.compat.v1.ConfigProto() if cpu_count is not None: config.inter_op_parallelism_threads = 1 config.intra_op_parallelism_threads = cpu_count with self.cached_session("", graph=tf.Graph(), config=config) as sess: with tf.device(device): inputs = tf.Variable( tf.random.uniform(image_shape, dtype=tf.dtypes.float32) * 255, trainable=False, dtype=tf.dtypes.float32) scale = tf.constant(0.1, dtype=tf.dtypes.float32) outputs = distort_image_ops.adjust_hsv_in_yiq( inputs, 0, scale, 1) run_op = tf.group(outputs) sess.run(tf.compat.v1.global_variables_initializer()) for _ in xrange(warmup_rounds): sess.run(run_op) start = time.time() for _ in xrange(benchmark_rounds): sess.run(run_op) end = time.time() step_time = (end - start) / benchmark_rounds tag = "%s" % (cpu_count) if cpu_count is not None else "_all" print( "benchmarkAdjustSaturationInYiq_299_299_3_cpu%s step_time: %.2f us" % (tag, step_time * 1e6)) self.report_benchmark( name="benchmarkAdjustSaturationInYiq_299_299_3_cpu%s" % (tag), iters=benchmark_rounds, wall_time=step_time)
def _adjust_hue_in_yiq_tf(self, x_np, delta_h): x = tf.constant(x_np) y = distort_image_ops.adjust_hsv_in_yiq(x, delta_h, 1, 1) return y
def _adjust_saturation_in_yiq_tf(self, x_np, scale): x = tf.constant(x_np) y = distort_image_ops.adjust_hsv_in_yiq(x, 0, scale, 1) return y
def _adjust_value_in_yiq_tf(self, x_np, scale): x = tf.constant(x_np) y = distort_image_ops.adjust_hsv_in_yiq(x, 0, 1, scale) return y