# Buggy code
def to_deeper_graph(graph):
    weighted_layer_ids = graph.deep_layer_ids()
    if len(weighted_layer_ids) >= Constant.MAX_MODEL_DEPTH:
        return None

    deeper_layer_ids = sample(weighted_layer_ids, 1)
    # n_deeper_layer = randint(1, len(weighted_layer_ids))
    # deeper_layer_ids = sample(weighted_layer_ids, n_deeper_layer)

    for layer_id in deeper_layer_ids:
        layer = graph.layer_list[layer_id]
        if is_layer(layer, "Conv"):
            graph.to_conv_deeper_model(layer_id, randint(1, 2) * 2 + 1)
        else:
            graph.to_dense_deeper_model(layer_id)
    return graph


# Traceback (RuntimeError)
.....
Epoch 14: loss 0.9113655090332031, metric_value 0.9318181818181818
No loss decrease after 3 epochs
Father ID:  2
[('to_dense_deeper_model', 14), ('to_conv_deeper_model', 1, 5), ('to_add_skip_model', 20, 5), ('to_concat_skip_model', 1, 5), ('to_add_skip_model', 1, 20), ('to_wider_model', 5, 64), ('to_concat_skip_model', 20, 5), ('to_conv_deeper_model', 20, 5), ('to_dense_deeper_model', 18), ('to_concat_skip_model', 1, 20)]
Saving model.
Model ID: 7
Loss: tensor(0.9246, device='cuda:0')
Metric Value: 0.92739898989899
Training model  8
Traceback (most recent call last):
File "ak_my.py", line 15, in <module>
clf.fit(x_train, y_train, time_limit=12 * 60 * 60)
File "C:\Users\kmbmjn\Anaconda3\lib\site-packages\autokeras\image_supervised.py", line 238, in fit
run_searcher_once(train_data, test_data, self.path, int(time_remain))
File "C:\Users\kmbmjn\Anaconda3\lib\site-packages\autokeras\image_supervised.py", line 41, in run_searcher_once
searcher.search(train_data, test_data, timeout)
File "C:\Users\kmbmjn\Anaconda3\lib\site-packages\autokeras\search.py", line 173, in search
self.metric, self.loss, self.verbose)]))
File "C:\Users\kmbmjn\Anaconda3\lib\site-packages\autokeras\search.py", line 269, in train
verbose).train_model(**trainer_args)
File "C:\Users\kmbmjn\Anaconda3\lib\site-packages\autokeras\utils.py", line 101, in train_model
self._train()
File "C:\Users\kmbmjn\Anaconda3\lib\site-packages\autokeras\utils.py", line 122, in _train
outputs = self.model(inputs)
File "C:\Users\kmbmjn\Anaconda3\lib\site-packages\torch\nn\modules\module.py", line 477, in __call__
result = self.forward(*input, **kwargs)
File "C:\Users\kmbmjn\Anaconda3\lib\site-packages\autokeras\graph.py", line 607, in forward
temp_tensor = torch_layer(edge_input_tensor)
File "C:\Users\kmbmjn\Anaconda3\lib\site-packages\torch\nn\modules\module.py", line 477, in __call__
result = self.forward(*input, **kwargs)
File "C:\Users\kmbmjn\Anaconda3\lib\site-packages\torch\nn\modules\linear.py", line 55, in forward
return F.linear(input, self.weight, self.bias)
File "C:\Users\kmbmjn\Anaconda3\lib\site-packages\torch\nn\functional.py", line 1024, in linear
return torch.addmm(bias, input, weight.t())
RuntimeError: size mismatch, m1: [128 x 2], m2: [64 x 64] at c:\programdata\miniconda3\conda-bld\pytorch_1533090623466\work\aten\src\thc\generic/THCTensorMathBlas.cu:249

# Fixed code
def to_deeper_graph(graph):
    weighted_layer_ids = graph.deep_layer_ids()
    if len(weighted_layer_ids) >= Constant.MAX_MODEL_DEPTH:
        return None

    deeper_layer_ids = sample(weighted_layer_ids, 1)
    # n_deeper_layer = randint(1, len(weighted_layer_ids))
    # deeper_layer_ids = sample(weighted_layer_ids, n_deeper_layer)

    for layer_id in deeper_layer_ids:
        layer = graph.layer_list[layer_id]
        if is_layer(layer, "Conv"):
            graph.to_conv_deeper_model(layer_id, 3)
        else:
            graph.to_dense_deeper_model(layer_id)
    return graph