| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -88,6 +88,7 @@ RUN apt-get install -y libfreetype6-dev && \ | |||
| 88 | 88 | pip install lightgbm==2.3.1 && \ | |
| 89 | 89 | pip install git+git://github.com/Lasagne/Lasagne.git && \ | |
| 90 | 90 | pip install keras && \ | |
| 91 | + pip install keras-tuner && \ | ||
| 91 | 92 | pip install flake8 && \ | |
| 92 | 93 | #neon | |
| 93 | 94 | cd /usr/local/src && \ | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,35 @@ | |||
| 1 | + import unittest | ||
| 2 | + | ||
| 3 | + import tensorflow as tf | ||
| 4 | + import numpy as np | ||
| 5 | + | ||
| 6 | + from kerastuner.tuners import RandomSearch | ||
| 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')) | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments