{
  "id": 590110,
  "title": "Still struggling with inference mode",
  "url": "/competitions/cmi-detect-behavior-with-sensor-data/discussion/590110",
  "author_name": "",
  "post_date": "2025-07-17T20:33:21.808132400Z",
  "votes": null,
  "comment_count": 2,
  "views": 0,
  "content": "<p>Hello everyone,<br>\nI'm still struggling to understand why I get an exception running (but I don't see any error on the log)<br>\nThe code of the notebook is: </p>\n<h1>-------------------------</h1>\n<h1>STEP 1 - IMPORT LIBRARIES &amp; LOAD MODEL</h1>\n<h1>-------------------------</h1>\n<p>import pandas as pd<br>\nimport numpy as np<br>\nimport joblib<br>\nfrom kaggle_evaluation.cmi_inference_server import CMIInferenceServer</p>\n<h1>Load model and label encoder</h1>\n<p>model = joblib.load(\"/kaggle/input/model_body_detection_behaviour/other/default/1/model.pkl\")<br>\nle = joblib.load(\"/kaggle/input/label_encoder/other/default/1/label_encoder.pkl\")</p>\n<h1>-------------------------</h1>\n<h1>STEP 2 - DEFINE PREDICT FUNCTION</h1>\n<h1>-------------------------</h1>\n<p>def predict(test_df: pd.DataFrame, test_demographics_df: pd.DataFrame) -&gt; pd.DataFrame:<br>\n    print(\"🔥🔥🔥 PREDICT() CALLED BY KAGGLE INFERENCE SERVER 🔥🔥🔥\")</p>\n<pre><code>imu_cols = \nthm_cols = \ntof_cols = \nsensor_cols = imu_cols + thm_cols + tof_cols\nagg_funcs = \n\npresent_cols = \ncols_to_use =  + present_cols\ndf_subset = test_df()\n\nX = df_subset()(agg_funcs)\nX = \nX(inplace=True)\n\nX_input = X(=[])\n\nexpected = model\nmissing = \n missing:\n    raise (f)\n\ny_pred = model(X_input)\ny_label = le(y_pred)\n\nresult_df = pd({\n    : X,\n    : y_label\n})\n\n\n(index=False))\nreturn result_df\n</code></pre>\n<h1>-------------------------</h1>\n<h1>STEP 3 - START INFERENCE SERVER</h1>\n<h1>-------------------------</h1>\n<p>inference_server = CMIInferenceServer(predict)<br>\ninference_server.serve()</p>\n<p>LOG:<br>\n\"Notebook threw Exception\" and the detailed log is (no errors actually):</p>\n<p>Time<br>\n#<br>\nLog Message<br>\n5.4s    1   0.00s - Debugger warning: It seems that frozen modules are being used, which may<br>\n5.4s    2   0.00s - make the debugger miss breakpoints. Please pass -Xfrozen_modules=off<br>\n5.4s    3   0.00s - to python to disable frozen modules.<br>\n5.4s    4   0.00s - Note: Debugging will proceed. Set PYDEVD_DISABLE_FILE_VALIDATION=1 to disable this validation.<br>\n6.4s    5   0.00s - Debugger warning: It seems that frozen modules are being used, which may<br>\n6.4s    6   0.00s - make the debugger miss breakpoints. Please pass -Xfrozen_modules=off<br>\n6.4s    7   0.00s - to python to disable frozen modules.<br>\n6.4s    8   0.00s - Note: Debugging will proceed. Set PYDEVD_DISABLE_FILE_VALIDATION=1 to disable this validation.<br>\n27.1s    9   /usr/local/lib/python3.11/dist-packages/traitlets/traitlets.py:2915: FutureWarning: --Exporter.preprocessors=[\"remove_papermill_header.RemovePapermillHeader\"] for containers is deprecated in traitlets 5.0. You can pass <code>--Exporter.preprocessors item</code> … multiple times to add items to a list.<br>\n27.1s    10    warn(<br>\n27.1s    11  [NbConvertApp] Converting notebook <strong>notebook</strong>.ipynb to notebook<br>\n27.5s    12  [NbConvertApp] Writing 4731 bytes to <strong>notebook</strong>.ipynb<br>\n29.2s    13  /usr/local/lib/python3.11/dist-packages/traitlets/traitlets.py:2915: FutureWarning: --Exporter.preprocessors=[\"nbconvert.preprocessors.ExtractOutputPreprocessor\"] for containers is deprecated in traitlets 5.0. You can pass <code>--Exporter.preprocessors item</code> … multiple times to add items to a list.<br>\n29.2s    14    warn(<br>\n29.2s    15  [NbConvertApp] Converting notebook <strong>notebook</strong>.ipynb to html<br>\n30.1s    16  [NbConvertApp] Writing 282129 bytes to <strong>results</strong>.html</p>\n<p>Can anyone help me please ?</p>",
  "messages": [
    {
      "id": "3250180",
      "postDate": "07/17/2025 20:33:21",
      "content": "<p>Hello everyone,<br>\nI'm still struggling to understand why I get an exception running (but I don't see any error on the log)<br>\nThe code of the notebook is: </p>\n<h1>-------------------------</h1>\n<h1>STEP 1 - IMPORT LIBRARIES &amp; LOAD MODEL</h1>\n<h1>-------------------------</h1>\n<p>import pandas as pd<br>\nimport numpy as np<br>\nimport joblib<br>\nfrom kaggle_evaluation.cmi_inference_server import CMIInferenceServer</p>\n<h1>Load model and label encoder</h1>\n<p>model = joblib.load(\"/kaggle/input/model_body_detection_behaviour/other/default/1/model.pkl\")<br>\nle = joblib.load(\"/kaggle/input/label_encoder/other/default/1/label_encoder.pkl\")</p>\n<h1>-------------------------</h1>\n<h1>STEP 2 - DEFINE PREDICT FUNCTION</h1>\n<h1>-------------------------</h1>\n<p>def predict(test_df: pd.DataFrame, test_demographics_df: pd.DataFrame) -&gt; pd.DataFrame:<br>\n    print(\"🔥🔥🔥 PREDICT() CALLED BY KAGGLE INFERENCE SERVER 🔥🔥🔥\")</p>\n<pre><code>imu_cols = \nthm_cols = \ntof_cols = \nsensor_cols = imu_cols + thm_cols + tof_cols\nagg_funcs = \n\npresent_cols = \ncols_to_use =  + present_cols\ndf_subset = test_df()\n\nX = df_subset()(agg_funcs)\nX = \nX(inplace=True)\n\nX_input = X(=[])\n\nexpected = model\nmissing = \n missing:\n    raise (f)\n\ny_pred = model(X_input)\ny_label = le(y_pred)\n\nresult_df = pd({\n    : X,\n    : y_label\n})\n\n\n(index=False))\nreturn result_df\n</code></pre>\n<h1>-------------------------</h1>\n<h1>STEP 3 - START INFERENCE SERVER</h1>\n<h1>-------------------------</h1>\n<p>inference_server = CMIInferenceServer(predict)<br>\ninference_server.serve()</p>\n<p>LOG:<br>\n\"Notebook threw Exception\" and the detailed log is (no errors actually):</p>\n<p>Time<br>\n#<br>\nLog Message<br>\n5.4s    1   0.00s - Debugger warning: It seems that frozen modules are being used, which may<br>\n5.4s    2   0.00s - make the debugger miss breakpoints. Please pass -Xfrozen_modules=off<br>\n5.4s    3   0.00s - to python to disable frozen modules.<br>\n5.4s    4   0.00s - Note: Debugging will proceed. Set PYDEVD_DISABLE_FILE_VALIDATION=1 to disable this validation.<br>\n6.4s    5   0.00s - Debugger warning: It seems that frozen modules are being used, which may<br>\n6.4s    6   0.00s - make the debugger miss breakpoints. Please pass -Xfrozen_modules=off<br>\n6.4s    7   0.00s - to python to disable frozen modules.<br>\n6.4s    8   0.00s - Note: Debugging will proceed. Set PYDEVD_DISABLE_FILE_VALIDATION=1 to disable this validation.<br>\n27.1s    9   /usr/local/lib/python3.11/dist-packages/traitlets/traitlets.py:2915: FutureWarning: --Exporter.preprocessors=[\"remove_papermill_header.RemovePapermillHeader\"] for containers is deprecated in traitlets 5.0. You can pass <code>--Exporter.preprocessors item</code> … multiple times to add items to a list.<br>\n27.1s    10    warn(<br>\n27.1s    11  [NbConvertApp] Converting notebook <strong>notebook</strong>.ipynb to notebook<br>\n27.5s    12  [NbConvertApp] Writing 4731 bytes to <strong>notebook</strong>.ipynb<br>\n29.2s    13  /usr/local/lib/python3.11/dist-packages/traitlets/traitlets.py:2915: FutureWarning: --Exporter.preprocessors=[\"nbconvert.preprocessors.ExtractOutputPreprocessor\"] for containers is deprecated in traitlets 5.0. You can pass <code>--Exporter.preprocessors item</code> … multiple times to add items to a list.<br>\n29.2s    14    warn(<br>\n29.2s    15  [NbConvertApp] Converting notebook <strong>notebook</strong>.ipynb to html<br>\n30.1s    16  [NbConvertApp] Writing 282129 bytes to <strong>results</strong>.html</p>\n<p>Can anyone help me please ?</p>",
      "rawMarkdown": "Hello everyone,\nI'm still struggling to understand why I get an exception running (but I don't see any error on the log)\nThe code of the notebook is: \n\n\n# -------------------------\n# STEP 1 - IMPORT LIBRARIES & LOAD MODEL\n# -------------------------\nimport pandas as pd\nimport numpy as np\nimport joblib\nfrom kaggle_evaluation.cmi_inference_server import CMIInferenceServer\n\n# Load model and label encoder\nmodel = joblib.load(\"/kaggle/input/model_body_detection_behaviour/other/default/1/model.pkl\")\nle = joblib.load(\"/kaggle/input/label_encoder/other/default/1/label_encoder.pkl\")\n\n# -------------------------\n# STEP 2 - DEFINE PREDICT FUNCTION\n# -------------------------\ndef predict(test_df: pd.DataFrame, test_demographics_df: pd.DataFrame) -> pd.DataFrame:\n    print(\"🔥🔥🔥 PREDICT() CALLED BY KAGGLE INFERENCE SERVER 🔥🔥🔥\")\n\n    imu_cols = ['acc_x', 'acc_y', 'acc_z', 'rot_w', 'rot_x', 'rot_y', 'rot_z']\n    thm_cols = [col for col in test_df.columns if col.startswith(\"thm_\")]\n    tof_cols = [col for col in test_df.columns if col.startswith(\"tof_\")]\n    sensor_cols = imu_cols + thm_cols + tof_cols\n    agg_funcs = ['mean', 'std', 'min', 'max']\n\n    present_cols = [col for col in sensor_cols if col in test_df.columns]\n    cols_to_use = ['sequence_id'] + present_cols\n    df_subset = test_df[cols_to_use].copy()\n\n    X = df_subset.groupby(\"sequence_id\").agg(agg_funcs)\n    X.columns = [\"_\".join(col) for col in X.columns]\n    X.reset_index(inplace=True)\n\n    X_input = X.drop(columns=[\"sequence_id\"])\n\n    expected = model.feature_names_in_\n    missing = [f for f in expected if f not in X_input.columns]\n    if missing:\n        raise ValueError(f\"❌ Missing features: {missing}\")\n\n    y_pred = model.predict(X_input)\n    y_label = le.inverse_transform(y_pred)\n\n    result_df = pd.DataFrame({\n        \"sequence_id\": X[\"sequence_id\"],\n        \"gesture\": y_label\n    })\n\n    print(\"✅ First 10 predictions:\")\n    print(result_df.head(10).to_string(index=False))\n    return result_df\n\n# -------------------------\n# STEP 3 - START INFERENCE SERVER\n# -------------------------\ninference_server = CMIInferenceServer(predict)\ninference_server.serve()\n\nLOG:\n\"Notebook threw Exception\" and the detailed log is (no errors actually):\n\nTime\n#\nLog Message\n5.4s\t1\t0.00s - Debugger warning: It seems that frozen modules are being used, which may\n5.4s\t2\t0.00s - make the debugger miss breakpoints. Please pass -Xfrozen_modules=off\n5.4s\t3\t0.00s - to python to disable frozen modules.\n5.4s\t4\t0.00s - Note: Debugging will proceed. Set PYDEVD_DISABLE_FILE_VALIDATION=1 to disable this validation.\n6.4s\t5\t0.00s - Debugger warning: It seems that frozen modules are being used, which may\n6.4s\t6\t0.00s - make the debugger miss breakpoints. Please pass -Xfrozen_modules=off\n6.4s\t7\t0.00s - to python to disable frozen modules.\n6.4s\t8\t0.00s - Note: Debugging will proceed. Set PYDEVD_DISABLE_FILE_VALIDATION=1 to disable this validation.\n27.1s\t9\t/usr/local/lib/python3.11/dist-packages/traitlets/traitlets.py:2915: FutureWarning: --Exporter.preprocessors=[\"remove_papermill_header.RemovePapermillHeader\"] for containers is deprecated in traitlets 5.0. You can pass `--Exporter.preprocessors item` ... multiple times to add items to a list.\n27.1s\t10\t  warn(\n27.1s\t11\t[NbConvertApp] Converting notebook __notebook__.ipynb to notebook\n27.5s\t12\t[NbConvertApp] Writing 4731 bytes to __notebook__.ipynb\n29.2s\t13\t/usr/local/lib/python3.11/dist-packages/traitlets/traitlets.py:2915: FutureWarning: --Exporter.preprocessors=[\"nbconvert.preprocessors.ExtractOutputPreprocessor\"] for containers is deprecated in traitlets 5.0. You can pass `--Exporter.preprocessors item` ... multiple times to add items to a list.\n29.2s\t14\t  warn(\n29.2s\t15\t[NbConvertApp] Converting notebook __notebook__.ipynb to html\n30.1s\t16\t[NbConvertApp] Writing 282129 bytes to __results__.html\n\nCan anyone help me please ?",
      "votes": null
    },
    {
      "id": "3250194",
      "postDate": "07/17/2025 21:21:06",
      "content": "<p>I feel your pain. Most of my issues were around torch.load but I see you're using raw pkl.</p>\n<p>Make sure Python versions match</p>\n<p>Try some of these tests after your predict fn has been defined: <a href=\"https://www.kaggle.com/code/robboyd/cmi-smoke-test\" target=\"_blank\">https://www.kaggle.com/code/robboyd/cmi-smoke-test</a></p>",
      "rawMarkdown": "I feel your pain. Most of my issues were around torch.load but I see you're using raw pkl.\n\nMake sure Python versions match\n\nTry some of these tests after your predict fn has been defined: https://www.kaggle.com/code/robboyd/cmi-smoke-test",
      "votes": null
    },
    {
      "id": "3250228",
      "postDate": "07/17/2025 23:17:25",
      "content": "<p>Predict is supposed to return a string. I am not sure why it says it can return a pandas dataframe but it can't. </p>",
      "rawMarkdown": "Predict is supposed to return a string. I am not sure why it says it can return a pandas dataframe but it can't.",
      "votes": null
    }
  ],
  "comments": [
    {
      "id": 3250194,
      "author_name": "robboyd",
      "author_url": "",
      "post_date": "07/17/2025 21:21:06",
      "content": "<p>I feel your pain. Most of my issues were around torch.load but I see you're using raw pkl.</p>\n<p>Make sure Python versions match</p>\n<p>Try some of these tests after your predict fn has been defined: <a href=\"https://www.kaggle.com/code/robboyd/cmi-smoke-test\" target=\"_blank\">https://www.kaggle.com/code/robboyd/cmi-smoke-test</a></p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 3250228,
      "author_name": "devinanzelmo",
      "author_url": "",
      "post_date": "07/17/2025 23:17:25",
      "content": "<p>Predict is supposed to return a string. I am not sure why it says it can return a pandas dataframe but it can't. </p>",
      "votes": null,
      "replies": []
    }
  ],
  "raw_markdown_by_id": {
    "3250180": "Hello everyone,\nI'm still struggling to understand why I get an exception running (but I don't see any error on the log)\nThe code of the notebook is: \n\n\n# -------------------------\n# STEP 1 - IMPORT LIBRARIES & LOAD MODEL\n# -------------------------\nimport pandas as pd\nimport numpy as np\nimport joblib\nfrom kaggle_evaluation.cmi_inference_server import CMIInferenceServer\n\n# Load model and label encoder\nmodel = joblib.load(\"/kaggle/input/model_body_detection_behaviour/other/default/1/model.pkl\")\nle = joblib.load(\"/kaggle/input/label_encoder/other/default/1/label_encoder.pkl\")\n\n# -------------------------\n# STEP 2 - DEFINE PREDICT FUNCTION\n# -------------------------\ndef predict(test_df: pd.DataFrame, test_demographics_df: pd.DataFrame) -> pd.DataFrame:\n    print(\"🔥🔥🔥 PREDICT() CALLED BY KAGGLE INFERENCE SERVER 🔥🔥🔥\")\n\n    imu_cols = ['acc_x', 'acc_y', 'acc_z', 'rot_w', 'rot_x', 'rot_y', 'rot_z']\n    thm_cols = [col for col in test_df.columns if col.startswith(\"thm_\")]\n    tof_cols = [col for col in test_df.columns if col.startswith(\"tof_\")]\n    sensor_cols = imu_cols + thm_cols + tof_cols\n    agg_funcs = ['mean', 'std', 'min', 'max']\n\n    present_cols = [col for col in sensor_cols if col in test_df.columns]\n    cols_to_use = ['sequence_id'] + present_cols\n    df_subset = test_df[cols_to_use].copy()\n\n    X = df_subset.groupby(\"sequence_id\").agg(agg_funcs)\n    X.columns = [\"_\".join(col) for col in X.columns]\n    X.reset_index(inplace=True)\n\n    X_input = X.drop(columns=[\"sequence_id\"])\n\n    expected = model.feature_names_in_\n    missing = [f for f in expected if f not in X_input.columns]\n    if missing:\n        raise ValueError(f\"❌ Missing features: {missing}\")\n\n    y_pred = model.predict(X_input)\n    y_label = le.inverse_transform(y_pred)\n\n    result_df = pd.DataFrame({\n        \"sequence_id\": X[\"sequence_id\"],\n        \"gesture\": y_label\n    })\n\n    print(\"✅ First 10 predictions:\")\n    print(result_df.head(10).to_string(index=False))\n    return result_df\n\n# -------------------------\n# STEP 3 - START INFERENCE SERVER\n# -------------------------\ninference_server = CMIInferenceServer(predict)\ninference_server.serve()\n\nLOG:\n\"Notebook threw Exception\" and the detailed log is (no errors actually):\n\nTime\n#\nLog Message\n5.4s\t1\t0.00s - Debugger warning: It seems that frozen modules are being used, which may\n5.4s\t2\t0.00s - make the debugger miss breakpoints. Please pass -Xfrozen_modules=off\n5.4s\t3\t0.00s - to python to disable frozen modules.\n5.4s\t4\t0.00s - Note: Debugging will proceed. Set PYDEVD_DISABLE_FILE_VALIDATION=1 to disable this validation.\n6.4s\t5\t0.00s - Debugger warning: It seems that frozen modules are being used, which may\n6.4s\t6\t0.00s - make the debugger miss breakpoints. Please pass -Xfrozen_modules=off\n6.4s\t7\t0.00s - to python to disable frozen modules.\n6.4s\t8\t0.00s - Note: Debugging will proceed. Set PYDEVD_DISABLE_FILE_VALIDATION=1 to disable this validation.\n27.1s\t9\t/usr/local/lib/python3.11/dist-packages/traitlets/traitlets.py:2915: FutureWarning: --Exporter.preprocessors=[\"remove_papermill_header.RemovePapermillHeader\"] for containers is deprecated in traitlets 5.0. You can pass `--Exporter.preprocessors item` ... multiple times to add items to a list.\n27.1s\t10\t  warn(\n27.1s\t11\t[NbConvertApp] Converting notebook __notebook__.ipynb to notebook\n27.5s\t12\t[NbConvertApp] Writing 4731 bytes to __notebook__.ipynb\n29.2s\t13\t/usr/local/lib/python3.11/dist-packages/traitlets/traitlets.py:2915: FutureWarning: --Exporter.preprocessors=[\"nbconvert.preprocessors.ExtractOutputPreprocessor\"] for containers is deprecated in traitlets 5.0. You can pass `--Exporter.preprocessors item` ... multiple times to add items to a list.\n29.2s\t14\t  warn(\n29.2s\t15\t[NbConvertApp] Converting notebook __notebook__.ipynb to html\n30.1s\t16\t[NbConvertApp] Writing 282129 bytes to __results__.html\n\nCan anyone help me please ?",
    "3250194": "I feel your pain. Most of my issues were around torch.load but I see you're using raw pkl.\n\nMake sure Python versions match\n\nTry some of these tests after your predict fn has been defined: https://www.kaggle.com/code/robboyd/cmi-smoke-test",
    "3250228": "Predict is supposed to return a string. I am not sure why it says it can return a pandas dataframe but it can't."
  },
  "source": "meta"
}