77import numpy as np
88from keras .datasets import mnist
99from keras .models import Sequential
10- from keras .layers import Conv2D , MaxPooling2D , Dropout , Flatten , Dense
10+ from keras .layers import Dense , Dropout , Flatten , Conv2D , MaxPooling2D
1111from keras .wrappers .scikit_learn import KerasClassifier
1212from modAL .models import ActiveLearner
1313
@@ -18,8 +18,10 @@ def create_keras_model():
1818 This function compiles and returns a Keras model.
1919 Should be passed to KerasClassifier in the Keras scikit-learn API.
2020 """
21+
2122 model = Sequential ()
2223 model .add (Conv2D (32 , kernel_size = (3 , 3 ), activation = 'relu' , input_shape = (28 , 28 , 1 )))
24+ model .add (Conv2D (64 , (3 , 3 ), activation = 'relu' ))
2325 model .add (MaxPooling2D (pool_size = (2 , 2 )))
2426 model .add (Dropout (0.25 ))
2527 model .add (Flatten ())
@@ -68,20 +70,21 @@ def create_keras_model():
6870learner = ActiveLearner (
6971 estimator = classifier ,
7072 X_training = X_initial , y_training = y_initial ,
71- verbose = 0
73+ verbose = 1
7274)
7375
7476# the active learning loop
7577n_queries = 10
7678for idx in range (n_queries ):
7779 query_idx , query_instance = learner .query (X_pool , n_instances = 200 , verbose = 0 )
80+ print (query_idx )
7881 learner .teach (
7982 X = X_pool [query_idx ], y = y_pool [query_idx ],
80- verbose = 0
83+ verbose = 1
8184 )
8285 # remove queried instance from pool
8386 X_pool = np .delete (X_pool , query_idx , axis = 0 )
8487 y_pool = np .delete (y_pool , query_idx , axis = 0 )
8588
8689# the final accuracy score
87- print (learner .score (X_test , y_test , verbose = 0 ))
90+ print (learner .score (X_test , y_test , verbose = 1 ))
0 commit comments