我正在尝试为Tensorflow构建新的卷积函数,该函数使用Multi Processing进行更快的计算。我是Tensorflow的新手,所以我不明白要使我的函数与现有代码一起使用,我到底需要做什么。
这是现有的Tensorflow代码:
def conv2d(x,W):
print("Applying convolution...")
#res = tf.nn.conv2d(x,W,strides=[1,1,1,1],padding='SAME') #This is the original function which is used.
res = myconv.myconv(x) #This is my function which I want to use for convolution operation
return res
我设计的函数的代码如下:
def myconv(img):
print("Inside myconv...")
processes_list = []
p1 = multiprocessing.Process(target=task1, args=(img,))
p2 = multiprocessing.Process(target=task2, args=(img,))
p3 = multiprocessing.Process(target=task3, args=(img,))
p4 = multiprocessing.Process(target=task4, args=(img,))
p5 = multiprocessing.Process(target=task5, args=(img,))
processes = []
processes.append(p1)
processes.append(p2)
processes.append(p3)
processes.append(p4)
processes.append(p5)
processes_list.append(processes)
p1.start()
p2.start()
p3.start()
p4.start()
p5.start()
active = len(multiprocessing.active_children())
count_proc = 0
for i in range(0, len(processes_list)):
obj = processes_list[i]
for j in range(0, len(obj)):
processes_list[i][j].join()
count_proc += 1
op_list=[]
temp="/home/piyushraut/PycharmProjects/Tensorflow Env/Intermediate/task"
for i in range(1,6):
fname=temp+str(i)+".jpg"
#print(fname)
op_list.append(cv2.imread(fname,0))
print(op_list)
return op_list
但是当我尝试同时运行这些代码时,出现以下错误:
回溯(最近通话最近):
文件 “ / home / piyushraut / PycharmProjects / Tensorflow Env / mnist_cnn.py”,行 74,在train_cnn(x) File "/home/piyushraut/PycharmProjects/Tensorflow Env/mnist_cnn.py", line 53, in train_cnn prediction = cnn(x) File "/home/piyushraut/PycharmProjects/Tensorflow Env/mnist_cnn.py", line
39,在cnn中 conv1 = tf.nn.relu(conv2d(x,weights ['W_conv1'])+ biases ['b_conv1'])
文件
“ / home / piyushraut / .local / lib / python3.5 / site-packages / tensorflow / python / ops / variables.py”, _run_op中的第856行 返回getattr(ops.Tensor,operator)(a._AsTensor(),* args)
文件“ /home/piyushraut/.local/lib/python3.5/site-packages/tensorflow/python/ops/math_ops.py”, r_binary_op_wrapper中的第893行 x = ops.convert_to_tensor(x,dtype = y.dtype.base_dtype,name =“ x”)
文件 “ /home/piyushraut/.local/lib/python3.5/site-packages/tensorflow/python/framework/ops.py”, 第1050行,在convert_to_tensor中 as_ref = False)
文件“ /home/piyushraut/.local/lib/python3.5/site-packages/tensorflow/python/framework/ops.py”, 第1146行,位于internal_convert_to_tensor中 ret = conversion_func(值,dtype = dtype,名称=名称,as_ref = as_ref)
文件 “ /home/piyushraut/.local/lib/python3.5/site-packages/tensorflow/python/framework/constant_op.py”, _constant_tensor_conversion_function中的第229行 返回常量(v,dtype = dtype,name = name)
文件“ /home/piyushraut/.local/lib/python3.5/site-packages/tensorflow/python/framework/constant_op.py”, 第208行,常数 值,dtype = dtype,shape = shape,verify_shape = verify_shape))
文件“ /home/piyushraut/.local/lib/python3.5/site-packages/tensorflow/python/framework/tensor_util.py”, make_tensor_proto中的第442行 _AssertCompatible(values,dtype)
文件“ /home/piyushraut/.local/lib/python3.5/site-packages/tensorflow/python/framework/tensor_util.py”, _AssertCompatible中的第353行 (dtype.name,repr(不匹配),类型(不匹配)。名称)。)TypeError:预期为float32,得到了数组([[0,0,0,...,0,0,0 ], [0,0,0,...,0,0,0], [0,0,0,...,0,0,0], ..., [0,0,0,...,0,0,0], [0,0,0,...,0,0,0], 代替[0,0,0,...,0,0,0]],dtype = uint8)的类型为'ndarray'。
我是Tensorflow的新手,所以我无法理解这里到底是什么问题。 有人可以帮我解决这个问题吗?