This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def neural_net_model(inputs, mode): | |
| with tf.variable_scope('ConvModel'): | |
| inputs = inputs / 255 | |
| input_layer = tf.reshape(inputs, [-1, 28, 28, 1]) | |
| conv1 = tf.layers.conv2d( | |
| inputs=input_layer, | |
| filters=20, | |
| kernel_size=[5, 5], | |
| padding='valid', | |
| activation=tf.nn.relu) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def model_fn(features, labels, mode): | |
| logits = neural_net_model(features, mode) | |
| class_prediction = tf.argmax(logits, axis=-1) | |
| preds = class_prediction | |
| loss = None | |
| train_op = None | |
| eval_metric_ops = {} | |
| if mode in (tf.estimator.ModeKeys.EVAL, tf.estimator.ModeKeys.TRAIN): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def model_fn(features, labels, mode, params, config) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| iris = datasets.load_iris() | |
| X = iris.data[:, :2] | |
| Y = iris.target | |
| clf = MLPClassifier(solver='lbfgs', hidden_layer_sizes=(10,10)) | |
| # Create an instance of Logistic Regression Classifier and fit the data. | |
| clf.fit(X, Y) | |
| # Prediction phase |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Build 2 hidden layer DNN with 10, 10 units respectively. | |
| classifier = tf.estimator.DNNClassifier( | |
| feature_columns=my_feature_columns, | |
| # Two hidden layers of 10 nodes each. | |
| hidden_units=[10, 10], | |
| # The model must choose between 3 classes. | |
| n_classes=3, | |
| # The directory which model to be saved | |
| model_dir='./tmp' | |
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| _NumericColumn(key='SepalLength', shape=(1,), default_value=None, dtype=tf.float32, normalizer_fn=None) | |
| _NumericColumn(key='SepalWidth', shape=(1,), default_value=None, dtype=tf.float32, normalizer_fn=None) | |
| _NumericColumn(key='PetalLength', shape=(1,), default_value=None, dtype=tf.float32, normalizer_fn=None) | |
| _NumericColumn(key='PetalWidth', shape=(1,), default_value=None, dtype=tf.float32, normalizer_fn=None) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def input_fn(): | |
| ... # manipulate dataset, extracting the feature dict and the label | |
| return feature_dict, label |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Feature columns describe how to use the input. | |
| my_feature_columns = [] | |
| for key in iris_data.train_x.keys(): | |
| my_feature_columns.append(tf.feature_column.numeric_column(key=key)) | |
| # Build 2 hidden layer DNN with 10, 10 units respectively. | |
| classifier = tf.estimator.DNNClassifier( | |
| feature_columns=my_feature_columns, | |
| # Two hidden layers of 10 nodes each. | |
| hidden_units=[10, 10], |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| elems = np.array(['H', 'e', 'l', 'l', 'o', ' ', 'T', 'e', 'n', 's', 'o', 'r']) | |
| sum = tf.scan(lambda a, x: a + x, elems) | |
| >>> ['H' 'He' 'Hel' 'Hell' 'Hello' 'Hello ' 'Hello T' 'Hello Te' | |
| 'Hello Ten' 'Hello Tens' 'Hello Tenso' 'Hello Tensor'] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| training_data = np.random.rand(3,20) | |
| training_labels = np.random.rand(3,1) | |
| with tf.Session(): | |
| input_data = tf.constant(training_data) | |
| input_labels = tf.constant(training_labels) | |
| ... |