Folowing tutorial but having error in the model loading step

Hi, Deepchem community,

I am following the tutorial for practicing, however, I kept getting the error when loading “model”.

For example, in this step,

import numpy as np

model.fit(train_dataset,nb_epoch=10)
metric = dc.metrics.Metric(dc.metrics.roc_auc_score)
print(‘training set score:’, model.evaluate(train_dataset, [metric], transformers))
print(‘test set score:’, model.evaluate(test_dataset, [metric], transformers))


AttributeError Traceback (most recent call last)
Cell In[49], line 3
1 import numpy as np
----> 3 model.fit(train_dataset,nb_epoch=10)
4 metric = dc.metrics.Metric(dc.metrics.roc_auc_score)
5 print(‘training set score:’, model.evaluate(train_dataset, [metric], transformers))

File ~/anaconda3/envs/mdanalysis-dev/lib/python3.11/site-packages/deepchem/models/keras_model.py:320, in KerasModel.fit(self, dataset, nb_epoch, max_checkpoints_to_keep, checkpoint_interval, deterministic, restore, variables, loss, callbacks, all_losses)
271 def fit(self,
272 dataset: Dataset,
273 nb_epoch: int = 10,
(…)
280 callbacks: Union[Callable, List[Callable]] = [],
281 all_losses: Optional[List[float]] = None) -> float:
282 “”“Train this model on a dataset.
283
284 Parameters
(…)
318 The average loss over the most recent checkpoint interval
319 “””
–> 320 return self.fit_generator(
321 self.default_generator(
322 dataset, epochs=nb_epoch,
323 deterministic=deterministic), max_checkpoints_to_keep,
324 checkpoint_interval, restore, variables, loss, callbacks, all_losses)

File ~/anaconda3/envs/mdanalysis-dev/lib/python3.11/site-packages/deepchem/models/keras_model.py:402, in KerasModel.fit_generator(self, generator, max_checkpoints_to_keep, checkpoint_interval, restore, variables, loss, callbacks, all_losses)
400 self.restore()
401 restore = False
–> 402 inputs, labels, weights = self._prepare_batch(batch)
404 # Execute the loss function, accumulating the gradients.
406 if len(inputs) == 1:

File ~/anaconda3/envs/mdanalysis-dev/lib/python3.11/site-packages/deepchem/models/keras_model.py:950, in KerasModel._prepare_batch(self, batch)
945 def _prepare_batch(self,
946 batch: Tuple[Any, Any, Any]) -> Tuple[List, List, List]:
947 inputs, labels, weights = batch
948 inputs = [
949 x if x.dtype == t else x.astype(t)
–> 950 for x, t in zip(inputs, self._input_dtypes)
951 ]
952 if labels is not None:
953 labels = [
954 x if x.dtype == t else x.astype(t)
955 for x, t in zip(labels, self._label_dtypes)
956 ]

AttributeError: ‘MultitaskClassifier’ object has no attribute ‘_input_dtypes’

Or in this step,

Define a neural network model

model = dc.models.GraphConvModel(n_tasks=1, mode=‘regression’, dropout=0.2)


ValueError Traceback (most recent call last)
Cell In[4], line 2
1 # Define a neural network model
----> 2 model = dc.models.GraphConvModel(n_tasks=1, mode=‘regression’, dropout=0.2)
3 #model.batch_norms = [
4 # BatchNormalization() if batch_normalize else None
5 # for _ in range(len(model.graph_conv_layers) + 1)
6 #]

File ~/anaconda3/envs/mdanalysis-dev/lib/python3.11/site-packages/deepchem/models/graph_models.py:945, in GraphConvModel.init(self, n_tasks, graph_conv_layers, dense_layer_size, dropout, mode, number_atom_features, n_classes, batch_size, batch_normalize, uncertainty, **kwargs)
943 self.batch_size = batch_size
944 self.uncertainty = uncertainty
–> 945 model = _GraphConvKerasModel(
946 n_tasks,
947 graph_conv_layers=graph_conv_layers,
948 dense_layer_size=dense_layer_size,
949 dropout=dropout,
950 mode=mode,
951 number_atom_features=number_atom_features,
952 n_classes=n_classes,
953 batch_normalize=batch_normalize,
954 uncertainty=uncertainty,
955 batch_size=batch_size)
956 if mode == “classification”:
957 output_types = [‘prediction’, ‘loss’, ‘embedding’]

File ~/anaconda3/envs/mdanalysis-dev/lib/python3.11/site-packages/deepchem/models/graph_models.py:811, in _GraphConvKerasModel.init(self, n_tasks, graph_conv_layers, dense_layer_size, dropout, mode, number_atom_features, n_classes, batch_normalize, uncertainty, batch_size)
804 raise ValueError(
805 ‘Dropout must be included in every layer to predict uncertainty’)
807 self.graph_convs = [
808 layers.GraphConv(layer_size, activation_fn=tf.nn.relu)
809 for layer_size in graph_conv_layers
810 ]
–> 811 self.batch_norms = [
812 BatchNormalization(fused=False) if batch_normalize else None
813 for _ in range(len(graph_conv_layers) + 1)
814 ]
815 self.dropouts = [
816 Dropout(rate=rate) if rate > 0.0 else None for rate in dropout
817 ]
818 self.graph_pools = [layers.GraphPool() for _ in graph_conv_layers]

File ~/anaconda3/envs/mdanalysis-dev/lib/python3.11/site-packages/deepchem/models/graph_models.py:812, in (.0)
804 raise ValueError(
805 ‘Dropout must be included in every layer to predict uncertainty’)
807 self.graph_convs = [
808 layers.GraphConv(layer_size, activation_fn=tf.nn.relu)
809 for layer_size in graph_conv_layers
810 ]
811 self.batch_norms = [
–> 812 BatchNormalization(fused=False) if batch_normalize else None
813 for _ in range(len(graph_conv_layers) + 1)
814 ]
815 self.dropouts = [
816 Dropout(rate=rate) if rate > 0.0 else None for rate in dropout
817 ]
818 self.graph_pools = [layers.GraphPool() for _ in graph_conv_layers]

File ~/anaconda3/envs/mdanalysis-dev/lib/python3.11/site-packages/keras/src/layers/normalization/batch_normalization.py:143, in BatchNormalization.init(self, axis, momentum, epsilon, center, scale, beta_initializer, gamma_initializer, moving_mean_initializer, moving_variance_initializer, beta_regularizer, gamma_regularizer, beta_constraint, gamma_constraint, synchronized, **kwargs)
125 def init(
126 self,
127 axis=-1,
(…)
141 **kwargs,
142 ):
–> 143 super().init(**kwargs)
144 self.axis = int(axis)
146 if synchronized and backend.backend() != “tensorflow”:

File ~/anaconda3/envs/mdanalysis-dev/lib/python3.11/site-packages/keras/src/layers/layer.py:264, in Layer.init(self, activity_regularizer, trainable, dtype, autocast, name, **kwargs)
262 self._input_shape_arg = input_shape_arg
263 if kwargs:
–> 264 raise ValueError(
265 “Unrecognized keyword arguments "
266 f"passed to {self.class.name}: {kwargs}”
267 )
269 self.built = False
270 self.autocast = autocast

ValueError: Unrecognized keyword arguments passed to BatchNormalization: {‘fused’: False}

I have updated my deepchem version as suggested by others.

Can someone direct me?

1 Like