Beispiel #1
0
def keras_train(
    train_data_path: str,
    model_path: str,
    # options
    epochs: int = 10,
    target_size: str = "600x800",
    overwrite: bool = False,
    **kwargs,
):
    from stagesepx.classifier.keras import KerasClassifier

    # handle args
    target_size: typing.Sequence[int] = [
        int(each) for each in target_size.split("x")
    ]

    cl = KerasClassifier(
        # 轮数
        epochs=epochs,
        # 保证数据集的分辨率统一性
        target_size=target_size,
        **kwargs,
    )
    cl.train(train_data_path)

    # file existed
    while os.path.isfile(model_path):
        logger.warning(f"file {model_path} already existed")
        model_path = f"{uuid.uuid4()}.h5"
        logger.debug(f"trying to save it to {model_path}")
    cl.save_model(model_path, overwrite=overwrite)
Beispiel #2
0
def keras_train(
    train_data_path: str,
    model_path: str,
    # options
    epochs: int = 10,
    target_size: str = "600x800",
    overwrite: bool = False,
    **kwargs,
):
    from stagesepx.classifier.keras import KerasClassifier

    assert not os.path.isfile(model_path), f"file {model_path} already existed"
    # handle args
    target_size: typing.Sequence[int] = [
        int(each) for each in target_size.split("x")
    ]

    cl = KerasClassifier(
        # 轮数
        epochs=epochs,
        # 保证数据集的分辨率统一性
        target_size=target_size,
        **kwargs,
    )
    cl.train(train_data_path)
    cl.save_model(model_path, overwrite=overwrite)
def test_keras():
    # set epochs to 1 for quickly training (test only)
    cl = KerasClassifier(epochs=1)
    cl.train(CUTTER_RESULT_DIR)
    cl.save_model("haha.h5")
    # recreate
    cl = KerasClassifier()
    cl.load_model("haha.h5")
    stable, _ = cutter_res.get_range()
    classify_result = cl.classify(VIDEO_PATH, stable, keep_data=True)
    assert classify_result.to_dict()
Beispiel #4
0
def train_model_Keras(_train_picture_path, _model_file_name):
    cl = KerasClassifier(
        # 轮数
        epochs=10,
        compress_rate=0.2,
        # 保证数据集的分辨率统一性
        # target_size=(600, 800),
    )
    cl.train(_train_picture_path)
    cl.save_model(_model_file_name, overwrite=True)

    return cl
Beispiel #5
0
        # overwrite this method to design your own model structure!

        # model  = Sequential()
        # ...
        pass

    def train(self, data_path: str, *_, **__):
        # ...
        pass


# or use the default one
# and then init it
# epochs=1 is just a example
cl = KerasClassifier(epochs=1)

# train model and save weights
cl.train(data_home)
cl.save_model("keras_model.h5")

# you would better reuse the trained model for less time cost
# keras model takes much more time than SVM
# cl.load_model("keras_model.h5")

classify_result = cl.classify(video, stable, keep_data=True)
result_dict = classify_result.to_dict()

# --- draw ---
r = Reporter()
r.draw(classify_result)
Beispiel #6
0
'''
 * @Description  : 开始根据图像数据训练模型及预测
 * @Autor        : Tommy
 * @Date         : 2021-02-21 18:51:11
 * @LastEditors  : Tommy
 * @LastEditTime : 2021-02-26 14:46:49
'''
from stagesepx.classifier.keras import KerasClassifier

# 训练模型文件
cl = KerasClassifier(
    # 设置这个数,需要保证小于总样本数,否则报错。
    # nb_train_samples=30,
    # 训练轮数
    epochs=30)

cl.train('./stable_frame')
cl.save_model('./model.h5', overwrite=True)
Beispiel #7
0
from stagesepx.classifier.keras import KerasClassifier

data_home = "./dataset"
model_file = "./keras_model.h5"

cl = KerasClassifier(
    # 轮数
    epochs=10,
    # 保证数据集的分辨率统一性
    target_size=(600, 800),
)
cl.train(data_home)
cl.save_model(model_file, overwrite=True)