在for循环中加载预先训练的模型会影响下一个文件的测试结果,因为在每个循环后预训练的权重不等于零

我正在使用keras,unet训练神经网络 . 我想用for循环加载所有模型并将它们单独放入测试生成器,但是,当我这样做时,测试结果会受到影响,因为预训练的权重不等于0 .

有没有人试过这个 .

我使用的代码是..

from model3a import *
from data import *
from matplotlib import pyplot as plt
import numpy
from keras.utils import plot_model
from PIL import Image
from io import BytesIO

def labelVisualize(num_class,color_dict,img):
    img = img[:,:,0] if len(img.shape) == 3 else img
    img_out = np.zeros(img.shape + (3,))
    for i in range(num_class):
        img_out[img == i,:] = color_dict[i]
    return img_out / 255




for filename in os.listdir('E:/unetTest/crossvalidation/val1/models'):
    if filename.endswith("hdf5"):
            #print(filename)
            file = open(filename,"r")
            print(filename)
            testGene = testGenerator("data")
            model= unet()
            #model.pretrained_weights= [0]
            #pretrained_weights = None
            #model= unet()
            #model.pretrained_weights = None
            #print(filename)
            model.load_weights(filename, "r")
            #print(model.pretrained_weights)
            results = model.predict_generator(testGene,19,verbose=1)
            saveResult("data",results)
            #model.pretrained_weights = None
            model.load_weights(0)

model3a是我的unet,数据包含几个函数,如testGenerator .

提前致谢

回答(0)