这是一个小例子,我想根据计算结束时得到的值对批处理进行采样。
myArray
这是我定义获取批处理的函数的位置。
with tf.Session() as sess:
conditional_val = tf.Variable(0, trainable=False)
print("get labels")
images, labels = get_img_and_label(data_dir, batch_size, conditional_val)
print("infer")
logits = inference(images)
print("define loss")
loss = compute_loss(logits,labels)
for i range(1000):
if i < 1:
_, loss_value = sess.run([loss])
else:
_, loss_value = sess.run([loss],feed_dict={conditional_val: index})
index = int(np.around(i*loss_value)[0])
它一直给我错误:
def get_img_and_labelS(data_dir,batch_size,conditional_val=0):
with open(data_dir) as datafile:
data = json.load(datafile)
inputs = data.keys()
input_names = []
for i in range(len(inputs)):
input_names.append(data_dir + inputs[i] + '.png')
for f in input_names:
if not tf.gfile.Exists(f):
raise ValueError('Failed to find file: ' + f)
images = []
labels = []
for i in range(len(input_names)):
# Load images with PILLOW (PIL Library)
my_img = Image.open(input_names[i])
images.append(np.array(my_img))
labels.append(data[inputs[i]][0])
images = images[0*conditional_val:20*conditional_val]
labels = labels[0*conditional_val:20*conditional_val]
return(images,labels)
有什么好方法可以做我想做的事情吗? 谢谢!