Determine whether a model is pytorch model or a tensorflow model or scikit model
If I want to determine the type of model i.e. from which framework was it made programmatically, is there a way to do that? 
I have a model in some serialized manner(Eg. a pickle file). For simplicity purposes, assume that my model can be either tensorflow's, pytorch's or scikit learn's. How can I determine programmatically which one of these 3 is the one?


AFAIK, I have never heard of Tensorflow/Keras and Pytorch models to be saved  with pickle or joblib - these frameworks provide their own functionality for saving &amp; loading models: see the SO threads Tensorflow: how to save/restore a model? and Best way to save a trained model in PyTorch?. Additionally, there is a Github thread reporting all kinds of issues when trying to save Tensorflow models with pickle and joblib.
Given that, if you have loaded a model with, say, pickle, it is trivial to see what type it is using type(model) and model. Here is a short demonstration with a scikit-learn linear regression model:
import numpy as np
from sklearn.linear_model import LinearRegression

X = np.array([[1, 1], [1, 2], [2, 2], [2, 3]])
y = np.dot(X, np.array([1, 2])) + 3
reg = LinearRegression()
reg.fit(X, y)

# save it

import pickle

filename = 'model1.pkl'
pickle.dump(reg, open(filename, 'wb'))

Now, loading the model:
loaded_model = pickle.load(open(filename, 'rb'))

type(loaded_model)
# sklearn.linear_model._base.LinearRegression

loaded_model
# LinearRegression(copy_X=True, fit_intercept=True, n_jobs=None, normalize=False)

This will also work with frameworks like XGBoost, LightGBM, CatBoost etc.
