Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/326.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/tensorflow/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 在tensorflow中并行运行预先训练的VGG-16_Python_Tensorflow_Parallel Processing_Vgg Net - Fatal编程技术网

Python 在tensorflow中并行运行预先训练的VGG-16

Python 在tensorflow中并行运行预先训练的VGG-16,python,tensorflow,parallel-processing,vgg-net,Python,Tensorflow,Parallel Processing,Vgg Net,我使用预先训练过的VGG-16网络将图像转换为特征。我可以做得很好。然而,我想并行地完成这项工作,我不确定如何正确地构造批处理 具体来说,假设我加载了保存在numpy数组中的16个图像(即16x224x224x3)。我想并行地转换这些。以下是我目前掌握的情况: checkpoint_file = './vgg_16.ckpt' input_tensor = tf.placeholder(tf.float32, shape=(None,224,224,3), name='input_image

我使用预先训练过的VGG-16网络将图像转换为特征。我可以做得很好。然而,我想并行地完成这项工作,我不确定如何正确地构造批处理

具体来说,假设我加载了保存在numpy数组中的16个图像(即16x224x224x3)。我想并行地转换这些。以下是我目前掌握的情况:

 checkpoint_file = './vgg_16.ckpt'
 input_tensor = tf.placeholder(tf.float32, shape=(None,224,224,3), name='input_image')
 scaled_input_tensor = tf.scalar_mul((1.0/255), input_tensor)
 scaled_input_tensor = tf.subtract(scaled_input_tensor, 0.5)
 scaled_input_tensor = tf.multiply(scaled_input_tensor, 2.0)

 arg_scope = vgg_arg_scope()
 with slim.arg_scope(arg_scope):
   _, end_points = vgg_16(scaled_input_tensor, is_training=False)

 sess = tf.Session()
 saver = tf.train.Saver()
 saver.restore(sess, checkpoint_file)

 images = get_16_images() #arbitrary function, images is 16x224x224x3
 images =  tf.convert_to_tensor(images)

 batch = tf.train.batch(im, 2, num_threads=6, enqueue_many=True, allow_smaller_final_batch=True)

 sess.run(end_points['vgg_16/fc7'], feed_dict={input_tensor: batch}) #Error
我最终得到一个错误:

***ValueError:使用序列设置数组元素


有人能帮我吗?批处理教程似乎侧重于在读取数据时创建批处理,但我已经读取了数据,只想创建一个批处理来并行网络对不同图像的计算。

好的,这是一个愚蠢的问题,但我认为其他tensorflow新手可能会遇到同样的问题

如果不清楚,
feed\u dict
接收numpy数组。所以你不需要构造一个显式的批处理张量。只需传入多个numpy数组,tensorflow就会处理它。注意我定义输入张量的地方:

input_tensor = tf.placeholder(tf.float32, shape=(None,224,224,3), name='input_image')
因此tensorflow已经知道输入可以说是一个“批处理”。变量
images
(来自
get\u 16\u images()
)正是我所需要的

您可以通过检查CPU分配来确认这是并行的。该批的Python CPU分配峰值高达650%