File: tf_separable_conv.py

package info (click to toggle)
halide 14.0.0-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 49,124 kB
  • sloc: cpp: 238,722; makefile: 4,303; python: 4,047; java: 1,575; sh: 1,384; pascal: 211; xml: 165; javascript: 43; ansic: 34
file content (22 lines) | stat: -rw-r--r-- 689 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import tensorflow as tf
import time

with tf.device('/GPU:0'):

    img = tf.random.uniform([4, 112, 112, 32])
    depthwise_filter = tf.random.uniform([3, 3, 32, 1])
    pointwise_filter = tf.random.uniform([1, 1, 32 * 1, 16])
    
    best = None
    num_trials = 10
    num_iter = 10
    for j in range(num_trials):
        start = time.time()
        for i in range(num_iter):
            out = tf.nn.separable_conv2d(
                img, depthwise_filter, pointwise_filter,
                strides = (1, 1, 1, 1), padding = 'VALID')
        end = time.time()
        t = (end - start) / num_iter
        if not best or t < best: best = t
    print('time: {} ms'.format(1000 * best))