keras当中对MobileNet进行fine-tuning出现的错误:we expect the tensors to have a static batch size

之前在进行MobileNet的fine-tuning的时候,出现了以下的问题

ValueError: When feeding symbolic tensors to a model, we expect thetensors to have a static batch size. Got tensor with shape: (None, 128, 128, 3)

部分代码如下:

image,label,oneHotlabel,imagePath=itertor.get_next()
model.fit(x=image,y=oneHotlabel,batch_size=11,epochs=10)
#image为从TFRecodes文件当中读取的111*128*128*3的111张图片
#oneHotlabel为每张图片对应的独热(one-hot)编码

经过虽然keras可以直接传入Tensor数据作为数据训练的数据,但是不接受类似于这种(None,128,128,3)的输入数据,然而TensorFlow当中可以使用占位符进行定义输入以及输出从而接收None,128,128,3)大小的Tensor数据的输入。此时如果不指定具体有多少张图片便会出现文章一开头的错误。

通过将代码改为:

with tf.Session() as sess:
    image,label,oneHotlabel,imagePath=itertor.get_next()
    image,oneHotlabel=sess.run([image,oneHotlabel])
    model.fit(x=image,y=oneHotlabel,batch_size=11,epochs=10)

通过在指定的session当中吧图片数据变为确定的numpy的ndarry形式便可以解决这一错误。

PS:在对MobileNet的fine-tuning的时候出现了各种奇奇怪怪的问题,除了这个之外,另外的问题还有:

keras当中对MobileNet进行fine-tuning出现的错误we expect the tensors to have a static batch size

keras当中对MobileNet进行fine-tuning出现的错误:could not create a dilated convolution forward descriptor

keras当中对MobileNe进行fine-tuning出现的错误:Attempting to use uninitialized value

 

你可能感兴趣的:(Python)