# Buggy code
def from_config(cls, config):
    blocks = [deserialize(block) for block in config["blocks"]]
    nodes = {
        int(node_id): deserialize(node) for node_id, node in config["nodes"].items()
    }
    override_hps = [
        kerastuner.engine.hyperparameters.deserialize(config)
        for config in config["override_hps"]
    ]

    inputs = [nodes[node_id] for node_id in nodes]
    for block_id, block in enumerate(blocks):
        input_nodes = [
            nodes[node_id] for node_id in config["block_inputs"][str(block_id)]
        ]
        output_nodes = nest.flatten(block(input_nodes))
        for output_node, node_id in zip(
            output_nodes, config["block_outputs"][str(block_id)]
        ):
            nodes[node_id] = output_node

    outputs = [nodes[node_id] for node_id in config["outputs"]]
    return cls(inputs=inputs, outputs=outputs, override_hps=override_hps)


# Traceback (TypeError)
Traceback (most recent call last):
File "mnist_model.py", line 12, in <module>
clf = ak.ImageClassifier(metrics=['accuracy', custom_metric], max_trials=3)
File "/home/lhs18285/miniconda3/envs/nas/lib/python3.7/site-packages/autokeras/tasks/image.py", line 67, in __init__
seed=seed)
File "/home/lhs18285/miniconda3/envs/nas/lib/python3.7/site-packages/autokeras/tasks/image.py", line 19, in __init__
**kwargs)
File "/home/lhs18285/miniconda3/envs/nas/lib/python3.7/site-packages/autokeras/auto_model.py", line 125, in __init__
project_name=name)
File "/home/lhs18285/miniconda3/envs/nas/lib/python3.7/site-packages/autokeras/tuners/task_specific.py", line 66, in __init__
**kwargs)
File "/home/lhs18285/miniconda3/envs/nas/lib/python3.7/site-packages/autokeras/tuners/greedy.py", line 197, in __init__
**kwargs)
File "/home/lhs18285/miniconda3/envs/nas/lib/python3.7/site-packages/autokeras/engine/tuner.py", line 35, in __init__
graph_module.serialize(self.hypermodel.hypermodel))
File "/home/lhs18285/miniconda3/envs/nas/lib/python3.7/site-packages/autokeras/utils.py", line 179, in save_json
obj = json.dumps(obj)
File "/home/lhs18285/miniconda3/envs/nas/lib/python3.7/json/__init__.py", line 231, in dumps
return _default_encoder.encode(obj)
File "/home/lhs18285/miniconda3/envs/nas/lib/python3.7/json/encoder.py", line 199, in encode
chunks = self.iterencode(o, _one_shot=True)
File "/home/lhs18285/miniconda3/envs/nas/lib/python3.7/json/encoder.py", line 257, in iterencode
return _iterencode(o, 0)
File "/home/lhs18285/miniconda3/envs/nas/lib/python3.7/json/encoder.py", line 179, in default
raise TypeError(f'Object of type {o.__class__.__name__} '
TypeError: Object of type function is not JSON serializable

# Fixed code
def from_config(cls, config):
    blocks = [hypermodels.deserialize(block) for block in config["blocks"]]
    nodes = {
        int(node_id): nodes_module.deserialize(node)
        for node_id, node in config["nodes"].items()
    }
    override_hps = [
        kerastuner.engine.hyperparameters.deserialize(config)
        for config in config["override_hps"]
    ]

    inputs = [nodes[node_id] for node_id in nodes]
    for block_id, block in enumerate(blocks):
        input_nodes = [
            nodes[node_id] for node_id in config["block_inputs"][str(block_id)]
        ]
        output_nodes = nest.flatten(block(input_nodes))
        for output_node, node_id in zip(
            output_nodes, config["block_outputs"][str(block_id)]
        ):
            nodes[node_id] = output_node

    outputs = [nodes[node_id] for node_id in config["outputs"]]
    return cls(inputs=inputs, outputs=outputs, override_hps=override_hps)