我在Tensorflow中使用tf.py_func有什么问题?

时间:2019-07-25 19:34:05

标签: python tensorflow

这是一个简化的代码段,在这里我缩小了范围。我基本上是在尝试通过自定义函数定义渐变路径。任何想法为什么这不起作用?:

import tensorflow as tf
import tensorflow.contrib.slim as slim
import tensorflow.contrib.slim.nets as nets
import PIL
import numpy as np

texture_model = tf.placeholder(tf.float32, (1,191440, 4, 4, 4, 3))
def render_texture(textures):
    return textures
render_sess = tf.py_func(render_texture, [texture_model], tf.float32)


def inception(image, reuse):
    preprocessed = tf.multiply(tf.subtract(tf.expand_dims(image, 0), 0.5), 2.0)
    arg_scope = nets.inception.inception_v3_arg_scope(weight_decay=0.0)
    with slim.arg_scope(arg_scope):
        logits, _ = nets.inception.inception_v3(
            preprocessed, 1001, is_training=False, reuse=reuse)
        logits = logits[:,1:] # ignore background class
        probs = tf.nn.softmax(logits) # probabilities
    return logits, probs


tf.logging.set_verbosity(tf.logging.ERROR)
sess = tf.InteractiveSession()

logits, probs = inception(render_sess, reuse=False) 

这只是给我这个错误;

Traceback (most recent call last):
  File "./examples/new_adv_method_debugging.py", line 54, in <module>
    logits, probs = inception(render_sess, reuse=False) #TODO: Modified. 
  File "./examples/new_adv_method_debugging.py", line 42, in inception
    preprocessed, 1001, is_training=False, reuse=reuse)
  File "/home/cs_u/anaconda2/lib/python2.7/site-packages/tensorflow/contrib/slim/python/slim/nets/inception_v3.py", line 580, in inception_v3
    depth_multiplier=depth_multiplier)
  File "/home/cs_u/anaconda2/lib/python2.7/site-packages/tensorflow/contrib/slim/python/slim/nets/inception_v3.py", line 112, in inception_v3_base
    net = layers.conv2d(inputs, depth(32), [3, 3], stride=2, scope=end_point)
  File "/home/cs_u/anaconda2/lib/python2.7/site-packages/tensorflow/contrib/framework/python/ops/arg_scope.py", line 182, in func_with_args
    return func(*args, **current_args)
  File "/home/cs_u/anaconda2/lib/python2.7/site-packages/tensorflow/contrib/layers/python/layers/layers.py", line 1159, in convolution2d
    conv_dims=2)
  File "/home/cs_u/anaconda2/lib/python2.7/site-packages/tensorflow/contrib/framework/python/ops/arg_scope.py", line 182, in func_with_args
    return func(*args, **current_args)
  File "/home/cs_u/anaconda2/lib/python2.7/site-packages/tensorflow/contrib/layers/python/layers/layers.py", line 1025, in convolution
    (conv_dims + 2, input_rank))
TypeError: %d format: a number is required, not NoneType

0 个答案:

没有答案
相关问题