How to convert a string to a tensorflow model?
So, I have created this model
model1 and I am trying to create a function which takes in different models like
model2 etc and evaluates them. In the process, I have a string called
"model1" which I would like to convert to
model1 so I can pass the
.evaluate() method to it. Would this be possible?
Assuming that your previously trained models are saved to disk, you may just want to load them back into memory and evaluate as:
model_names = ["model1", "model2", "model3", ..., "model10"] for model_name in model_names: model = tf.keras.models.load_model("path/to/location/" + model_name) score = model.evaluate(X_test, y_test, ...)
Also, if you plan to have lots of models with sequential names, like model1, model2, …, model_n, you can use list comprehension instead of hard coding the model names like:
model_names = ["model" + str(x) for x in range(1, n)]
Please note that these are pseudo-codes and you need to complete … according to your needs.
Answered By – ihpar