BayesianRNN icon indicating copy to clipboard operation
BayesianRNN copied to clipboard

Initialization of self._predict_stochastic

Open jjkernst opened this issue 8 years ago • 2 comments

Hi, I am attempting to run the Examples/sentiment_lstm_regression.py however I am running into some issues: it keeps failing on the initialization of the predict_stochastic function in the first callback of modeltest.

First the function fails on X = models.standardize_X(X), due to the below error. Is this function supposed to be standardize(X)? I can't find a standardize_X in the latest Keras pull (I am using 1.0.3)? AttributeError: 'module' object has no attribute 'standardize_X'

The function then also fails on defining the K function because neither model.X_test nor model.y_train are defined. The example doesn't have a test set passed into the fit model, so I'm not sure which variable this would be referencing. K.function([self.model.X_test], [self.model.y_train]) AttributeError: 'Sequential' object has no attribute 'X_test'

If I remove the Modeltest call backs, the training works fine.

Any help you could provide would be greatly appreciated. Thanks!

jjkernst avatar Jun 06 '16 03:06 jjkernst

I fixed these issues with the following changes:

  • In callbacks.py, insert this at line 6:
def standardize_X(X):
    if type(X) == list:
        return X
    else:
        return [X]

then replace "X = models.standardize_X(X)" with "X = standardize_X(X)"

  • In callbacks.py, replace the line
self._predict_stochastic = K.function([self.model.X_test], [self.model.y_train])

with the following (using the Theano backend of Keras):

self._predict_stochastic = K.function([self.model.inputs[0]],
                    [self.model.outputs[0]], givens={K.learning_phase(): np.uint8(1)})
  • I also had to insert this at line 51 of sentiment_lstm_regression.py:
X_train = np.asarray(X_train)
X_test  = np.asarray(X_test)
Y_train = np.asarray(Y_train)
Y_test  = np.asarray(Y_test)

jasonbunk avatar Jul 15 '16 05:07 jasonbunk

I fixed these issues with the following changes:

  • In callbacks.py, insert this at line 6:
def standardize_X(X):
    if type(X) == list:
        return X
    else:
        return [X]

then replace "X = models.standardize_X(X)" with "X = standardize_X(X)"

  • In callbacks.py, replace the line
self._predict_stochastic = K.function([self.model.X_test], [self.model.y_train])

with the following (using the Theano backend of Keras):

self._predict_stochastic = K.function([self.model.inputs[0]],
                    [self.model.outputs[0]], givens={K.learning_phase(): np.uint8(1)})
  • I also had to insert this at line 51 of sentiment_lstm_regression.py:
X_train = np.asarray(X_train)
X_test  = np.asarray(X_test)
Y_train = np.asarray(Y_train)
Y_test  = np.asarray(Y_test)

hi, thanks for your solution, furthermore, I want to clear which version of theano and keras used in above code?

Chealkeo avatar Jan 18 '21 02:01 Chealkeo