在对MobileNet进行fine-tuning的时候,出现了各种诡异的错误,在之前的博文介绍的错误当中,因为要将批量的图片数据通过指定的session转化为ndarry数据,因此代码如下
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之后运行的时候,网络却报出师徒尝试使用为初始化的值的错误,这也是莫名其妙,因为我的网络是采用keras的API直接实现fine-tuning的并不是采用TensorFlow完成编写的,部分代码如下:
x = base_model.get_layer("conv_pw_11_relu").output # 获得conv_pw_12_relu层的输出
x = Conv2D(512, kernel_size=(3, 3))(x)
x = Activation("relu")(x)
x = AvgPool2D(pool_size=(5, 5))(x)
x = Dropout(rate=0.5)(x)
x=Conv2D(class_num,kernel_size=(1,1))(x)
x=Reshape((class_num,))(x)
predictions=Softmax()(x) #输出对各个类别的分类概率
# finet