class_docstr: A 1, 2, or 3 dimensional convolutional network for either regression or classification.
  
  The network consists of the following sequence of layers:
  
  - A configurable number of convolutional layers
  - A global pooling layer (either max pool or average pool)
  - A final fully connected layer to compute the output
  
  It optionally can compose the model from pre-activation residual blocks, as
  described in https://arxiv.org/abs/1603.05027, rather than a simple stack of
  convolution layers.  This often leads to easier training, especially when using a
  large number of layers.  Note that residual blocks can only be used when
  successive layers have the same output shape.  Wherever the output shape changes, a
  simple convolution layer will be used even if residual=True.
  
  Examples
  --------
  >>> import deepchem as dc
  >>> n_samples = 10
  >>> n_features = 3
  >>> n_tasks = 1
  >>> np.random.seed(123)
  >>> X = np.random.rand(n_samples, 10, n_features)
  >>> y = np.random.randint(2, size=(n_samples, n_tasks)).astype(np.float32)
  >>> dataset: dc.data.Dataset = dc.data.NumpyDataset(X, y)
  >>> regression_metric = dc.metrics.Metric(dc.metrics.mean_squared_error)
  >>> model = CNN(n_tasks, n_features, dims=1, kernel_size=3, mode='regression')
  >>> avg_loss = model.fit(dataset, nb_epoch=10)
code: def default_generator(
      self,
      dataset,
      epochs=1,
      mode="fit",
      deterministic=True,
      pad_batches=True,
  ):
      for epoch in range(epochs):
          for X_b, y_b, w_b, ids_b in dataset.iterbatches(
              batch_size=self.batch_size,
              deterministic=deterministic,
              pad_batches=pad_batches,
          ):
              if self.mode == "classification":
                  if y_b is not None:
                      y_b = to_one_hot(
                          y_b.flatten(), self.n_classes
                      ).reshape(-1, self.n_tasks, self.n_classes)
  
              dropout = (
                  np.array(0.0) if mode == "predict" else np.array(1.0)
              )
  
              yield ([X_b, dropout], [y_b], [w_b])
  
file_path: deepchem/deepchem/models/torch_models/cnn.py
imports: import torch
  import numpy
  from deepchem.models.torch_models.torch_model import TorchModel
  from deepchem.models.torch_models.layers import CNNModule
  from deepchem.models.losses import L2Loss
  from deepchem.metrics import to_one_hot
  from typing import List, Union, Callable, Optional
  from deepchem.utils.typing import OneOrMany, ActivationFn, LossFn
label_desc: Use image node_id 2 for calling the CNN obj's underlying member method code with example usage: obj.default_generator(dataset, epochs, mode, deterministic, pad_batches) without return types