| 7 | |
| 8 | |
| 9 | class TestKerasTuner(unittest.TestCase): |
| 10 | def test_search(self): |
| 11 | def build_model(hp): |
| 12 | x_train = np.random.random((100, 28, 28)) |
| 13 | y_train = np.random.randint(10, size=(100, 1)) |
| 14 | x_test = np.random.random((20, 28, 28)) |
| 15 | y_test = np.random.randint(10, size=(20, 1)) |
| 16 | |
| 17 | model = tf.keras.models.Sequential([ |
| 18 | tf.keras.layers.Flatten(input_shape=(28, 28)), |
| 19 | tf.keras.layers.Dense(128, activation='relu'), |
| 20 | tf.keras.layers.Dropout(hp.Choice('dropout_rate', values=[0.2, 0.4])), |
| 21 | tf.keras.layers.Dense(10, activation='softmax') |
| 22 | ]) |
| 23 | |
| 24 | model.compile( |
| 25 | optimizer='adam', |
| 26 | loss='sparse_categorical_crossentropy', |
| 27 | metrics=['accuracy']) |
| 28 | |
| 29 | return model |
| 30 | |
| 31 | tuner = RandomSearch(build_model, objective='accuracy', max_trials=1, executions_per_trial=1, seed=1) |
| 32 | |
| 33 | tuner.search(x_train, y_train, epochs=1) |
| 34 | |
| 35 | self.assertEqual(0.4, tuner.get_best_hyperparameters(1)[0].get('dropout_rate')) |
nothing calls this directly
no outgoing calls
no test coverage detected