docstr: Simple example for a compute function using a feed forward network.
  It is trained on the MNIST dataset.
  The input parameter "config" (dictionary) contains the sampled configurations passed by the bohb optimizer
code: def compute(self, config, budget, working_directory, *args, **kwargs):
      """
      Simple example for a compute function using a feed forward network.
      It is trained on the MNIST dataset.
      The input parameter "config" (dictionary) contains the sampled configurations passed by the bohb optimizer
      """
  
      model = Sequential()
  
      model.add(
          Conv2D(
              config["num_filters_1"],
              kernel_size=(3, 3),
              activation="relu",
              input_shape=self.input_shape,
          )
      )
      model.add(MaxPooling2D(pool_size=(2, 2)))
  
      if config["num_conv_layers"] > 1:
          model.add(
              Conv2D(
                  config["num_filters_2"],
                  kernel_size=(3, 3),
                  activation="relu",
                  input_shape=self.input_shape,
              )
          )
          model.add(MaxPooling2D(pool_size=(2, 2)))
  
      if config["num_conv_layers"] > 2:
          model.add(
              Conv2D(
                  config["num_filters_3"],
                  kernel_size=(3, 3),
                  activation="relu",
                  input_shape=self.input_shape,
              )
          )
          model.add(MaxPooling2D(pool_size=(2, 2)))
  
      model.add(Dropout(config["dropout_rate"]))
      model.add(Flatten())
      model.add(Dense(config["num_fc_units"], activation="relu"))
      model.add(Dropout(config["dropout_rate"]))
      model.add(Dense(self.num_classes, activation="softmax"))
  
      if config["optimizer"] == "Adam":
          optimizer = keras.optimizers.Adam(lr=config["lr"])
      else:
          optimizer = keras.optimizers.SGD(
              lr=config["lr"], momentum=config["sgd_momentum"]
          )
  
      model.compile(
          loss=keras.losses.categorical_crossentropy,
          optimizer=optimizer,
          metrics=["accuracy"],
      )
  
      model.fit(
          self.x_train,
          self.y_train,
          batch_size=self.batch_size,
          epochs=int(budget),
          verbose=0,
          validation_data=(self.x_test, self.y_test),
      )
  
      train_score = model.evaluate(
          self.x_train, self.y_train, verbose=0
      )
      val_score = model.evaluate(
          self.x_validation, self.y_validation, verbose=0
      )
      test_score = model.evaluate(self.x_test, self.y_test, verbose=0)
  
      # import IPython; IPython.embed()
      return {
          "loss": 1
          - val_score[1],  # remember: HpBandSter always minimizes!
          "info": {
              "test accuracy": test_score[1],
              "train accuracy": train_score[1],
              "validation accuracy": val_score[1],
              "number of parameters": model.count_params(),
          },
      }
  
file_path: HpBandSter/docs/build/html/_downloads/example_5_keras_worker.py
imports: import ConfigSpace
  import ConfigSpace.hyperparameters
  from hpbandster.core.worker import Worker
  import logging
label_desc: Use image node_id 2 for calling the KerasWorker obj's underlying member method code with example usage: obj.compute(config, budget, working_directory) and returns: dict