![](/img/trans.png)
[英]InvalidArgumentError: You must feed a value for placeholder tensor 'Placeholder_1'
[英]Tensorflow: InvalidArgumentError: You must feed a value for placeholder tensor 'Placeholder_1'
对于下面的代码,我得到了上面的错误,该代码应该找到最适合源图像的圆锥部分:
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))。 出局应该只是(255,255,255),所以我不确定发生了什么。
我现在唯一看到的是您的输入并不正确。 您的占位符是:
pic = tf.placeholder(tf.int32, shape=(height, width))
out = tf.placeholder(tf.int32, shape=(height, width))
当图像的形状为(高度,宽度,3)<-颜色通道时
您可以尝试解决此问题,看看是否可行吗?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.