Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deeptable model can not work after loading model #92

Closed
BruceQD opened this issue Apr 22, 2024 · 1 comment
Closed

Deeptable model can not work after loading model #92

BruceQD opened this issue Apr 22, 2024 · 1 comment

Comments

@BruceQD
Copy link

BruceQD commented Apr 22, 2024

As shown in the figure, the model can successfully predict X_valid. However, after loading the model, the model does not have the predict_proba function, and using the predict function for prediction also results in an error.

1

The error message for newmodel.predict(X_valid) is as follows:

KeyError Traceback (most recent call last)
Cell In[19], line 1
----> 1 newmodel.predict(X_valid)

File /opt/conda/lib/python3.10/site-packages/deeptables/models/deepmodel.py:127, in DeepModel.predict(self, X, batch_size, verbose)
126 def predict(self, X, batch_size=128, verbose=0):
--> 127 return self.__predict(self.model, X, batch_size=batch_size, verbose=verbose)

File /opt/conda/lib/python3.10/site-packages/deeptables/models/deepmodel.py:131, in DeepModel.__predict(self, model, X, batch_size, verbose)
129 def __predict(self, model, X, batch_size=128, verbose=0):
130 logger.info("Performing predictions...")
--> 131 ds = self.__get_prediction_data(X, batch_size=batch_size)
132 steps = math.ceil(len(X) / batch_size)
133 return model.predict(ds, steps=steps, verbose=verbose)

File /opt/conda/lib/python3.10/site-packages/deeptables/models/deepmodel.py:207, in DeepModel.__get_prediction_data(self, X, y, batch_size)
206 def __get_prediction_data(self, X, y=None, *, batch_size):
--> 207 ds = to_dataset(self.config, self.task, self.num_classes, X, y,
208 batch_size=batch_size, shuffle=False, drop_remainder=False,
209 categorical_columns=self.categorical_columns,
210 continuous_columns=self.continuous_columns,
211 var_len_categorical_columns=self.var_len_categorical_columns)
213 return ds

File /opt/conda/lib/python3.10/site-packages/deeptables/utils/dataset_generator.py:246, in to_dataset(config, task, num_classes, X, y, batch_size, shuffle, drop_remainder, categorical_columns, continuous_columns, var_len_categorical_columns)
240 logger.info(f'create dataset generator with {cls.name}, '
241 f'batch_size={batch_size}, shuffle={shuffle}, drop_remainder={drop_remainder}')
243 dg = cls(config, task, num_classes, categorical_columns=categorical_columns,
244 continuous_columns=continuous_columns,
245 var_len_categorical_columns=var_len_categorical_columns)
--> 246 ds = dg(X, y, batch_size=batch_size, shuffle=shuffle, drop_remainder=drop_remainder)
247 return ds

File /opt/conda/lib/python3.10/site-packages/deeptables/utils/dataset_generator.py:44, in _TFDGForPandas.call(self, X, y, batch_size, shuffle, drop_remainder)
41 # add categorical data
42 if self.categorical_columns is not None and len(self.categorical_columns) > 0:
43 train_data['input_categorical_vars_all'] =
---> 44 X[[c.name for c in self.categorical_columns]].values.astype(consts.DATATYPE_TENSOR_FLOAT)
46 # add continuous data
47 if self.continuous_columns is not None and len(self.continuous_columns) > 0:

File /opt/conda/lib/python3.10/site-packages/pandas/core/frame.py:3899, in DataFrame.getitem(self, key)
3897 if is_iterator(key):
3898 key = list(key)
-> 3899 indexer = self.columns._get_indexer_strict(key, "columns")[1]
3901 # take() does not accept boolean indexers
3902 if getattr(indexer, "dtype", None) == bool:

File /opt/conda/lib/python3.10/site-packages/pandas/core/indexes/base.py:6114, in Index._get_indexer_strict(self, key, axis_name)
6111 else:
6112 keyarr, indexer, new_indexer = self._reindex_non_unique(keyarr)
-> 6114 self._raise_if_missing(keyarr, indexer, axis_name)
6116 keyarr = self.take(indexer)
6117 if isinstance(key, Index):
6118 # GH 42790 - Preserve name from an Index

File /opt/conda/lib/python3.10/site-packages/pandas/core/indexes/base.py:6178, in Index._raise_if_missing(self, key, indexer, axis_name)
6175 raise KeyError(f"None of [{key}] are in the [{axis_name}]")
6177 not_found = list(ensure_index(key)[missing_mask.nonzero()[0]].unique())
-> 6178 raise KeyError(f"{not_found} not in index")

KeyError: "

@oaksharks
Copy link
Collaborator

@BruceQD Please refer to this example: https://github.com/DataCanvasIO/DeepTables/blob/master/deeptables/examples/quickstart.ipynb

from hypernets.utils import fs

model_dir = "model_dir"
dt.save(model_dir)

print(f"Absolute path for the persisted model: {fs.remote_root_}/{model_dir}")

model_load = deeptable.DeepTable.load(model_dir)  # KEYPOINT
model_load.evaluate(df_test,y_test, batch_size=512, verbose=0)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants