| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -5,7 +5,7 @@ | |||
| 5 | 5 | import pandas as pd | |
| 6 | 6 | ||
| 7 | 7 | from keras.models import Sequential | |
| 8 | - from keras.layers import Dense, Dropout, Flatten, Conv2D, MaxPooling2D, CuDNNLSTM | ||
| 8 | + from keras.layers import Dense, Dropout, Flatten, Conv2D, MaxPooling2D, LSTM | ||
| 9 | 9 | from keras.optimizers import RMSprop, SGD | |
| 10 | 10 | from keras.utils.np_utils import to_categorical | |
| 11 | 11 | ||
@@ -62,29 +62,21 @@ def test_conv2d(self): | |||
| 62 | 62 | ||
| 63 | 63 | model.evaluate(x_test, y_test, batch_size=32) | |
| 64 | 64 | ||
| 65 | - # Tensorflow 2.0 doesn't support the contrib package. | ||
| 66 | - # | ||
| 67 | - # Error: | ||
| 68 | - # from tensorflow.contrib.cudnn_rnn.python.ops import cudnn_rnn_ops | ||
| 69 | - # ModuleNotFoundError: No module named 'tensorflow.contrib' | ||
| 70 | - # | ||
| 71 | - # tf.keras should be used instead until this is fixed. | ||
| 72 | - # @gpu_test | ||
| 73 | - # def test_cudnn_lstm(self): | ||
| 74 | - # x_train = np.random.random((100, 100, 100)) | ||
| 75 | - # y_train = keras.utils.to_categorical(np.random.randint(10, size=(100, 1)), num_classes=10) | ||
| 76 | - # x_test = np.random.random((20, 100, 100)) | ||
| 77 | - # y_test = keras.utils.to_categorical(np.random.randint(10, size=(20, 1)), num_classes=10) | ||
| 78 | - | ||
| 79 | - # sgd = SGD(lr=0.01, decay=1e-6, momentum=0.9, nesterov=True) | ||
| 80 | - | ||
| 81 | - # model = Sequential() | ||
| 82 | - # model.add(CuDNNLSTM(32, return_sequences=True, input_shape=(100, 100))) | ||
| 83 | - # model.add(Flatten()) | ||
| 84 | - # model.add(Dense(10, activation='softmax')) | ||
| 85 | - | ||
| 86 | - | ||
| 87 | - # model.compile(loss='categorical_crossentropy', optimizer=sgd) | ||
| 88 | - # model.fit(x_train, y_train, batch_size=32, epochs=1) | ||
| 89 | - # model.evaluate(x_test, y_test, batch_size=32) | ||
| 65 | + def test_lstm(self): | ||
| 66 | + x_train = np.random.random((100, 100, 100)) | ||
| 67 | + y_train = keras.utils.to_categorical(np.random.randint(10, size=(100, 1)), num_classes=10) | ||
| 68 | + x_test = np.random.random((20, 100, 100)) | ||
| 69 | + y_test = keras.utils.to_categorical(np.random.randint(10, size=(20, 1)), num_classes=10) | ||
| 70 | + | ||
| 71 | + sgd = SGD(lr=0.01, decay=1e-6, momentum=0.9, nesterov=True) | ||
| 72 | + | ||
| 73 | + model = Sequential() | ||
| 74 | + model.add(LSTM(32, return_sequences=True, input_shape=(100, 100))) | ||
| 75 | + model.add(Flatten()) | ||
| 76 | + model.add(Dense(10, activation='softmax')) | ||
| 77 | + | ||
| 78 | + | ||
| 79 | + model.compile(loss='categorical_crossentropy', optimizer=sgd) | ||
| 80 | + model.fit(x_train, y_train, batch_size=32, epochs=1) | ||
| 81 | + model.evaluate(x_test, y_test, batch_size=32) | ||
| 90 | 82 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments