Repository: keras-team/autokeras

Issue:
Add content to nas.md
<!---
Please label your issue with `feature_request`.
-->

### Feature Description
<!---
A clear and concise description of idea/feature. If it is related to some problem you are facing, then explain the problem.
-->
Add content to nas.md.
Add code examples for running different searchers on CIFAR10 in the examples folder.
The example should call the CnnModule.
The CIFAR10 dataset should be directly loaded from pytorch. (refer to example code of pytorch on CIFAR10 online)

### Reason
<!---
A clear and concise description of why this feature would be useful for the project.
-->

### Solution
<!---
A clear and concise description of what you want to happen.
-->

### Alternative Solutions
<!---
A clear and concise description of any alternative solutions or features you've considered.
-->

### Additional Context
<!---
Add any other context or screenshots about the feature request here.
-->



Discussion:

Resolving patch:
diff --git a/autokeras/search.py b/autokeras/search.py
--- a/autokeras/search.py
+++ b/autokeras/search.py
@@ -8,7 +8,7 @@
 import torch.multiprocessing as mp
 
 
-from abc import abstractmethod
+from abc import ABC, abstractmethod
 from datetime import datetime
 from autokeras.bayesian import BayesianOptimizer
 from autokeras.constant import Constant
@@ -16,7 +16,7 @@
 from autokeras.utils import pickle_to_file, pickle_from_file, verbose_print, get_system
 
 
-class Searcher:
+class Searcher(ABC):
     """The base class to search for neural architectures.
 
     This class generate new architectures, call the trainer to train it, and update the optimizer.
@@ -234,7 +234,6 @@ def generate(self, multiprocessing_queue):
         """
         pass
 
-    @abstractmethod
     def update(self, *args):
         pass
 
diff --git a/examples/nas/cifar10_tutorial.py b/examples/nas/cifar10_tutorial.py
new file mode 100644
--- /dev/null
+++ b/examples/nas/cifar10_tutorial.py
@@ -0,0 +1,60 @@
+"""
+Run NAS baseline methods
+========================
+We provide 4 NAS baseline methods now, the default one is bayesian optimization.
+Here is a tutorial about running NAS baseline methods.
+
+Generally, to run a non-default NAS methods, we will do the following steps in order:
+1. Prepare the dataset in the form of torch.utils.data.DataLoader.
+2. Initialize the CnnModule/MlpModule with the class name of the NAS Searcher.
+3. Start search by running fit function.
+Refer the cifar10 example below for more details.
+"""
+import numpy as np
+import torch
+import torchvision
+import torchvision.transforms as transforms
+from torch.nn.functional import cross_entropy
+
+from autokeras import CnnModule
+from autokeras.nn.metric import Accuracy
+from nas.greedy import GreedySearcher
+
+if __name__ == '__main__':
+    print('==> Preparing data..')
+    transform_train = transforms.Compose([
+        transforms.RandomCrop(32, padding=4),
+        transforms.RandomHorizontalFlip(),
+        transforms.ToTensor(),
+        transforms.Normalize((0.4914, 0.4822, 0.4465), (0.2023, 0.1994, 0.2010)),
+    ])
+
+    transform_test = transforms.Compose([
+        transforms.ToTensor(),
+        transforms.Normalize((0.4914, 0.4822, 0.4465), (0.2023, 0.1994, 0.2010)),
+    ])
+
+    trainset = torchvision.datasets.CIFAR10(root='./data', train=True,
+                                            download=True, transform=transform_train)
+    trainloader = torch.utils.data.DataLoader(trainset, batch_size=4,
+                                              shuffle=True, num_workers=2)
+
+    testset = torchvision.datasets.CIFAR10(root='./data', train=False,
+                                           download=True, transform=transform_test)
+    testloader = torch.utils.data.DataLoader(testset, batch_size=4,
+                                             shuffle=False, num_workers=2)
+    (image, target) = trainset[0]
+    image = np.array(image).transpose((1, 2, 0))
+    # add dim for batch
+    input_shape = np.expand_dims(image, axis=0).shape
+    num_classes = 10
+
+    # take GreedySearcher as an example, you can implement your own searcher and
+    # pass the class name to the CnnModule by search_type=YOUR_SEARCHER.
+    cnnModule = CnnModule(loss=cross_entropy, metric=Accuracy,
+                          searcher_args={}, verbose=True,
+                          search_type=GreedySearcher)
+
+    cnnModule.fit(n_output_node=num_classes, input_shape=input_shape,
+                  train_data=trainloader,
+                  test_data=testloader)
\ No newline at end of file
diff --git a/nas/__init__.py b/nas/__init__.py
new file mode 100644


Test patch: