code: def get_input_dimension(model):
      if hasattr(model, "n_features_"):
          return model.n_features_
  
      elif hasattr(model, "n_estimators"):
          if model.n_estimators == 0:
              raise ValueError("model not trained.")
  
          try:
              return model.estimators_[0, 0].n_features_
          except IndexError:
              raise ValueError("Model not trained or invalid model.")
      else:
          raise ValueError(
              "Unable to obtain input dimension from model."
          )
  
imports: from ..._deps import _HAS_SKLEARN
  from ...models._feature_management import process_or_validate_features
  from ...models.tree_ensemble import TreeEnsembleClassifier, TreeEnsembleRegressor
label_desc: Use image node_id 3 for calling a global function with example usage: get_input_dimension(model) and returns: model, model