Skip to content

Sample app forecasting with keras reload problem #121

@Marka10

Description

@Marka10

Function
PyTools.sklearn_Calculate_Metrics_Sequence

Describe the bug
Connector reply error: grpc::StatusCode::UNKNOWN: 'Exception iterating responses: 'str' object has no attribute 'decode''

Full error message from Python
2021-01-27 08:36:26,273 - INFO - ExecuteFunction (functionId: 42, _sklearn)
2021-01-27 08:36:26,337 - ERROR - Exception iterating responses: 'str' object has no attribute 'decode'
Traceback (most recent call last):
File "C:\Qlik\qlik-py-tools-8.0\qlik-py-env\lib\site-packages\grpc_server.py", line 453, in _take_response_from_response_iterator
return next(response_iterator), True
File "main.py", line 550, in _sklearn
response = model.calculate_metrics(ordered_data=True)
File "C:\Qlik\qlik-py-tools-8.0\qlik-py-env\core_sklearn.py", line 895, in calculate_metrics
self.X_test, self.y_test = self._get_model_and_data(target=True, ordered_data=ordered_data)
File "C:\Qlik\qlik-py-tools-8.0\qlik-py-env\core_sklearn.py", line 1927, in _get_model_and_data
self._get_model()
File "C:\Qlik\qlik-py-tools-8.0\qlik-py-env\core_sklearn.py", line 2459, in _get_model
self.model = self.model.load(self.model.name, self.path)
File "C:\Qlik\qlik-py-tools-8.0\qlik-py-env\core_machine_learning.py", line 132, in load
keras_model = keras.models.load_model(path + name + '.h5')
File "C:\Qlik\qlik-py-tools-8.0\qlik-py-env\lib\site-packages\keras\engine\saving.py", line 458, in load_wrapper
return load_function(*args, **kwargs)
File "C:\Qlik\qlik-py-tools-8.0\qlik-py-env\lib\site-packages\keras\engine\saving.py", line 550, in load_model
model = _deserialize_model(h5dict, custom_objects, compile)
File "C:\Qlik\qlik-py-tools-8.0\qlik-py-env\lib\site-packages\keras\engine\saving.py", line 242, in _deserialize_model
model_config = json.loads(model_config.decode('utf-8'))
AttributeError: 'str' object has no attribute 'decode'

Error message in Qlik
image

Expression or load script used in Qlik
Its the unaltered app "Sample-app-forecasting-with-keras"
...
For Each vModel in FieldValueList('Model Name')

If '$(vModel)' <> 'Bikes-CausalConv-7d-v1' Then

    // Other than the multi-step model we get evaluation metrics and predictions one month at a time.
    // Since past values are inputs to these models, predicting over long periods will add up the errors from previous predictions.
    // In practice, we can continue to provide actual values to the model
    // So we are going to get predictions one month at a time, supplying actual values for previous periods
    For Each vMonth in 7, 8, 9, 10, 11, 12

        // Prepare samples table with the current model name and unique keys
        [TEMP_SAMPLES_WITH_KEYS]:
        LOAD
           '$(vModel)' as Model_Name,
           Key,
           N_Features // Including Target for historical data. Target may be Null or zero for the periods to be predicted
        RESIDENT [TEMP_TEST]
        WHERE [Key] >= (MonthStart(MakeDate(2012, $(vMonth), 1))-31) and [Key] <= MonthEnd(MakeDate(2012, $(vMonth), 1)); 

        // Use the LOAD...EXTENSION syntax to call the Get_Metrics function
        [Result-Metrics]:
        LOAD *,
            MonthName(MakeDate(2012, $(vMonth), 1)) as MonthName
        EXTENSION PyTools.sklearn_Calculate_Metrics_Sequence(TEMP_SAMPLES_WITH_KEYS{Model_Name, Key, N_Features});

Environment:

  • Windows Server
  • Qlik Sense Enterprise november 2020
  • SSE Version PY-tools 8.0

Additional context
In searching the web in general for solutions it seems that h5py needs to be <2.5 and some have had success using a different solver than lbfgs.

Metadata

Metadata

Assignees

No one assigned

    Labels

    usage exceptionException during a SSE function call from Qlik

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions