Пример #1
0
class Model(ModelBase):
    def __init__(self):
        # load config file
        config = json.load(open("model/config.json"))
        # get the image processor
        self._imageProcessor = ImageProcessor(config)
        # load the DL model
        self._model = Xception()
        self._model.load_weights('model/model.h5')
        self._model._make_predict_function()

    def infer(self, input):
        # load preprocessed input
        inputAsNpArr = self._imageProcessor.loadAndPreprocess(input)
        # Run inference with caffe2
        results = self._model.predict(inputAsNpArr)
        # postprocess results into output
        output = self._imageProcessor.computeOutput(results)
        return output
Пример #2
0
                                  steps_per_epoch=x_train.shape[0] //
                                  batch_size)

else:
    History = model.fit_generator(datagen.flow(x_train,
                                               y_train,
                                               batch_size=batch_size),
                                  epochs=epochs,
                                  verbose=1,
                                  steps_per_epoch=x_train.shape[0] //
                                  batch_size)

#generate submission
if (options.save_submission):
    print("generate submission...")
    predict = np.argmax(model.predict(test), axis=1)
    output = pd.DataFrame(le.inverse_transform(predict))
    output.columns
    output.columns = ['Expected']
    output.index.name = "Id"
    output.to_csv("../submission/submission_" + options.model + versioninfo +
                  ".csv")

#save weight
if (options.save_weight):
    print("save weight...")
    model.save_weights("../weight/" + options.model + versioninfo + ".h5")

#save history
if (options.save_history):
    print("save history...")