【问题标题】:Tensorflow: InvalidArgumentError: You must feed a value for placeholder tensor 'Placeholder_1'Tensorflow:InvalidArgumentError:您必须为占位符张量“Placeholder_1”提供一个值
【发布时间】:2017-03-31 22:08:42
【问题描述】:

我得到以下代码的上述错误,该代码应该找到最适合源图像的圆锥部分:

import numpy as np
import tensorflow as tf
import cv2

# import image
img = cv2.imread('stinkbug.png')
height, width, channels = img.shape

# blur image
img = cv2.blur(img, (5, 5))

# posterize image
n = 4    # Number of levels of quantization
indices = np.arange(0,256)   # List of all colors
divider = np.linspace(0,255,n+1)[1] # we get a divider
quantiz = np.int0(np.linspace(0,255,n)) # we get quantization colors
color_levels = np.clip(np.int0(indices/divider),0,n-1) # color levels 0,1,2..
palette = quantiz[color_levels] # Creating the palette
im2 = palette[img]  # Applying palette on image
im2 = cv2.convertScaleAbs(im2) # Converting image back to uint8
img = im2

# create graph image
graph = np.zeros((height, width, 3), np.uint8)
graph[:] = (255, 255, 255)
cv2.imwrite('grf.png', graph)

# Model parameters
A = tf.Variable([20], tf.int32)
B = tf.Variable([20], tf.int32)
C = tf.Variable([20], tf.int32)
D = tf.Variable([20], tf.int32)
E = tf.Variable([20], tf.int32)
F = tf.Variable([20], tf.int32)
G = tf.Variable([20], tf.int32)
Red = tf.Variable([20], tf.int32)
Green = tf.Variable([20], tf.int32)
Blue = tf.Variable([20], tf.int32)

#inputs
pic = tf.placeholder(tf.int32, shape=(height, width))
out = tf.placeholder(tf.int32, shape=(height, width))

sess = tf.Session()

# model
def conic_model(x, y):
    tf.multiply(A, (x+F)) ** 2 + tf.multiply(tf.multiply(B, (x+F)), (y+G)) + tf.multiply(C, (y+G)) ** 2 + tf.multiply(D, (x+F)) + tf.multiply(E, (y+G))
def f1(): return (Red, Green, Blue)
def f2(): return (255, 255, 255)
decider = tf.cond(tf.less(conic_model(out.eval(session=sess), out[0].eval(session=sess)), 0), f1(), f2())
grf = decider

# loss
combo = tf.reduce_sum(tf.square(pic - grf))
loss = combo / (height * width)

# optimizer
optimizer = tf.train.GradientDescentOptimizer(0.01)
train = optimizer.minimize(loss)

# training loop
init = tf.global_variables_initializer()
sess.run(init)
for i in range(1000):
  sess.run(train, feed_dict={pic:img, out:graph})

错误发生在第 42 行,out = tf.placeholder(tf.int32, shape=(height, width))。 Out 应该是 (255, 255, 255),所以我不确定发生了什么。

【问题讨论】:

  • 你没有行号,所以我怀疑人们会数第 42 行。也许您可以编辑您的代码示例以指出错误所在的行。

标签: python tensorflow


【解决方案1】:

我现在唯一看到的是您的输入并不正确。您的占位符是:

pic = tf.placeholder(tf.int32, shape=(height, width))
out = tf.placeholder(tf.int32, shape=(height, width))

虽然您的图像具有形状(高度、宽度、3)

您可以尝试解决此问题,看看是否可行?

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-11-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-10-23
    • 1970-01-01
    相关资源
    最近更新 更多