# Buggy code
def fit(self, x, y, x_test=None, y_test=None, time_limit=None):
    x = np.array(x)
    y = np.array(y).flatten()
    validate_xy(x, y)
    y = self.transform_y(y)
    if x_test is None or y_test is None:
        # Divide training data into training and testing data.
        validation_set_size = int(len(y) * Constant.VALIDATION_SET_SIZE)
        validation_set_size = min(validation_set_size, 500)
        validation_set_size = max(validation_set_size, 1)
        x_train, x_test, y_train, y_test = train_test_split(
            x, y, test_size=validation_set_size, random_state=42
        )
    else:
        x_train = x
        y_train = y
    # Transform x_train
    if self.data_transformer is None:
        self.data_transformer = ImageDataTransformer(x, augment=self.augment)

    # Wrap the data into DataLoaders
    train_data = self.data_transformer.transform_train(x_train, y_train)
    test_data = self.data_transformer.transform_test(x_test, y_test)

    # Save the classifier
    pickle_to_file(self, os.path.join(self.path, "classifier"))

    if time_limit is None:
        time_limit = 24 * 60 * 60

    self.cnn.fit(
        self.get_n_output_node(), x_train.shape, train_data, test_data, time_limit
    )


# Traceback (RuntimeError)
╒==============================================╕
|               Training model 1               |
╘==============================================╛
Using TensorFlow backend.
Current Epoch:   0%|                             | 0/1 [00:00<?, ? batch/s]Exception ignored in: <bound method tqdm.__del__ of Current Epoch:   0%|                             | 0/1 [07:59<?, ? batch/s]>
Traceback (most recent call last):
File "/root/anaconda3/envs/automl-formal/lib/python3.6/site-packages/tqdm/_tqdm.py", line 885, in __del__
self.close()
File "/root/anaconda3/envs/automl-formal/lib/python3.6/site-packages/tqdm/_tqdm.py", line 1090, in close
self._decr_instances(self)
File "/root/anaconda3/envs/automl-formal/lib/python3.6/site-packages/tqdm/_tqdm.py", line 454, in _decr_instances
cls.monitor.exit()
File "/root/anaconda3/envs/automl-formal/lib/python3.6/site-packages/tqdm/_monitor.py", line 52, in exit
self.join()
File "/root/anaconda3/envs/automl-formal/lib/python3.6/threading.py", line 1053, in join
raise RuntimeError("cannot join current thread")
RuntimeError: cannot join current thread
multiprocessing.pool.RemoteTraceback:
"""
Traceback (most recent call last):
File "/root/anaconda3/envs/automl-formal/lib/python3.6/multiprocessing/pool.py", line 119, in worker
result = (True, func(*args, **kwds))
File "/root/anaconda3/envs/automl-formal/lib/python3.6/multiprocessing/pool.py", line 44, in mapstar
return list(map(*args))
File "/root/anaconda3/envs/automl-formal/lib/python3.6/site-packages/autokeras/search.py", line 296, in train
verbose=verbose).train_model(**trainer_args)
File "/root/anaconda3/envs/automl-formal/lib/python3.6/site-packages/autokeras/model_trainer.py", line 103, in train_model
self._train()
File "/root/anaconda3/envs/automl-formal/lib/python3.6/site-packages/autokeras/model_trainer.py", line 147, in _train
outputs = self.model(inputs)
File "/root/anaconda3/envs/automl-formal/lib/python3.6/site-packages/torch/nn/modules/module.py", line 477, in __call__
result = self.forward(*input, **kwargs)
File "/root/anaconda3/envs/automl-formal/lib/python3.6/site-packages/autokeras/graph.py", line 610, in forward
temp_tensor = torch_layer(edge_input_tensor)
File "/root/anaconda3/envs/automl-formal/lib/python3.6/site-packages/torch/nn/modules/module.py", line 477, in __call__
result = self.forward(*input, **kwargs)
File "/root/anaconda3/envs/automl-formal/lib/python3.6/site-packages/torch/nn/modules/batchnorm.py", line 66, in forward
exponential_average_factor, self.eps)
File "/root/anaconda3/envs/automl-formal/lib/python3.6/site-packages/torch/nn/functional.py", line 1254, in batch_norm
training, momentum, eps, torch.backends.cudnn.enabled
RuntimeError: $ Torch: not enough memory: you tried to allocate 0GB. Buy new RAM! at [/pytorch/aten/src/TH/THGeneral.cpp:204]

# Fixed code
def fit(self, x, y, x_test=None, y_test=None, time_limit=None):
    x = np.array(x)

    if len(x.shape) != 0 and len(x[0].shape) == 3:
        self.resize_height, self.resize_width = compute_image_resize_params(x)
        x = resize_image_data(x, self.resize_height, self.resize_width)
        if x_test is not None:
            x_test = resize_image_data(x_test, self.resize_height, self.resize_width)

    y = np.array(y).flatten()
    validate_xy(x, y)
    y = self.transform_y(y)
    if x_test is None or y_test is None:
        # Divide training data into training and testing data.
        validation_set_size = int(len(y) * Constant.VALIDATION_SET_SIZE)
        validation_set_size = min(validation_set_size, 500)
        validation_set_size = max(validation_set_size, 1)
        x_train, x_test, y_train, y_test = train_test_split(
            x, y, test_size=validation_set_size, random_state=42
        )
    else:
        x_train = x
        y_train = y
    # Transform x_train
    if self.data_transformer is None:
        self.data_transformer = ImageDataTransformer(x, augment=self.augment)

    # Wrap the data into DataLoaders
    train_data = self.data_transformer.transform_train(x_train, y_train)
    test_data = self.data_transformer.transform_test(x_test, y_test)

    # Save the classifier
    pickle_to_file(self, os.path.join(self.path, "classifier"))

    if time_limit is None:
        time_limit = 24 * 60 * 60

    self.cnn.fit(
        self.get_n_output_node(), x_train.shape, train_data, test_data, time_limit
    )