示例#1
0
def get_predictions(data_dir, preprocessing_function=lambda x: x, model=model):
    if isinstance(preprocessing_function, str):
        if preprocessing_function == 'fliplr':
            preprocessing_function = lambda x: x[..., ::-1, :]
        elif preprocessing_function in ('identity', 'orig'):
            preprocessing_function = lambda x: x
        else:
            raise ValueError('unknown preprocessing_function:\t%s' %
                             preprocessing_function)

    val_datagen = ImageDataGenerator(**norm_params)
    val_datagen.preprocessing_function = preprocessing_function
    datagen_val_output = val_datagen.flow_from_directory(data_dir,
                                                         shuffle=False,
                                                         **flowfromdir_params)

    gen_ = datagen_val_output
    yhat = model.predict_generator(
        gen_,
        steps=len(gen_),
        verbose=1,
    )

    dfdict = {"scores_%d" % nn: yy for nn, yy in enumerate(yhat.T)}
    dfdict.update({"files": gen_.filenames, "label": gen_.classes})
    dfres = pd.DataFrame(dfdict)
    return dfres
示例#2
0
    seed=prms.seed)

norm_params = dict(
    #rescale=prms.scaleup,
    samplewise_center=prms.samplewise_center,
    samplewise_std_normalization=prms.samplewise_center,
    featurewise_center=False,
    featurewise_std_normalization=False,
    zca_whitening=False,
)

# In[23]:

train_datagen = ImageDataGenerator(**norm_params)

train_datagen.preprocessing_function = lambda x: x[..., ::-1, :]  #*2**-8
datagen_train_output = train_datagen.flow_from_directory(
    prms.data_train,
    #stratify = prms.oversampling,
    #sampling_factor=prms.sampling_factor,
    #oversampling=prms.oversampling,
    shuffle=False,
    **flowfromdir_params)
SAMPLES_PER_EPOCH = len(datagen_train_output.filenames)
STEPS_PER_EPOCH = int(np.ceil(SAMPLES_PER_EPOCH / prms.batch_size))


##########################################
def get_predictions(data_dir, preprocessing_function=lambda x: x, model=model):
    if isinstance(preprocessing_function, str):
        if preprocessing_function == 'fliplr':