Tensorflow tensorfow tf.expand_dims错误
我是tensorflow的初学者,我使用了tf.expand_dims,我得到了错误,我不明白原因,所以我缺少了什么 这是密码Tensorflow tensorfow tf.expand_dims错误,tensorflow,conv-neural-network,Tensorflow,Conv Neural Network,我是tensorflow的初学者,我使用了tf.expand_dims,我得到了错误,我不明白原因,所以我缺少了什么 这是密码 ML_OUTPUT = None input_for_classification = None def ConstructML( input_tensor, layers_count, node_for_each_layer): global ML_OUTPUT global input_for_classification Featu
ML_OUTPUT = None
input_for_classification = None
def ConstructML( input_tensor, layers_count, node_for_each_layer):
global ML_OUTPUT
global input_for_classification
FeatureVector = np.array(input_tensor)
FeatureVector = FeatureVector.flatten()
print(FeatureVector.shape)
ML_ModelINT(FeatureVector, layers_count, node_for_each_layer)
def ML_ModelINT(FeatureVector, layers_count, node_for_each_layer):
hidden_layer = []
Alloutputs = []
hidden_layer.append({'weights': tf.Variable(tf.random_normal([FeatureVector.shape[0], node_for_each_layer[0]])),'biases': tf.Variable(tf.random_normal([node_for_each_layer[0]]))})
for i in range(1, layers_count):
hidden_layer.append({'weights': tf.Variable(tf.random_normal([node_for_each_layer[i - 1], node_for_each_layer[i]])),'biases': tf.Variable(tf.random_normal([node_for_each_layer[i]]))})
FeatureVector = tf.expand_dims(FeatureVector,0)
layers_output = tf.add(tf.matmul(FeatureVector, hidden_layer[0]['weights']), hidden_layer[0]['biases'])
layers_output = tf.nn.relu(layers_output)
Alloutputs.append(layers_output)
for j in range(1, layers_count):
layers_output = tf.add(tf.matmul(layers_output, hidden_layer[j]['weights']), hidden_layer[j]['biases'])
layers_output = tf.nn.relu(layers_output)
Alloutputs.append(layers_output)
ML_OUTPUT = layers_output
input_for_classification = Alloutputs[1]
return ML_OUTPUT
ML_Net = ConstructML(input,3,[1024,512,256])
这句话给了我一个错误
FeatureVector = tf.expand_dims(FeatureVector,0)
错误是预期的二进制或unicode字符串,得到tf.Tensor'Relu_11:0'shape=(?,7,7,512)dtype=float32
注意输入是另一个网络的输出张量,它工作得很好好的,numpy部分是错误的,因为当第一次调用prediction函数时,它还没有输入imgs的馈送,numpy代码将无法正确执行,我用tensorflow ops替换了它,现在它可以工作了。我想你的类型有些奇怪。。。在函数ConstructML中,FeatureVector是一个numpy数组。然后将其传递给ModelINT,并在其上运行tf张量操作,而不进行转换。。。