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
from dgl.nn.tensorflow import GraphConv | |
class GCN(tf.keras.Model): | |
def __init__(self, g, feat_dim, hidden_dim, class_num): | |
super(GCN, self).__init__() | |
self.g = g | |
self.h1 = GraphConv(feat_dim, hidden_dim, activation=tf.nn.relu, allow_zero_in_degree=True) | |
self.dropout = tf.keras.layers.Dropout(0.5) | |
self.h2 = GraphConv(hidden_dim, class_num), allow_zero_in_degree=True | |
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
model = tf.keras.models.Sequential() | |
model.add(tf.keras.layers.Input(shape=(1433,))) | |
model.add(tf.keras.layers.Dense(32, activation='relu')) | |
model.add(tf.keras.layers.Dropout(0.5)) | |
model.add(tf.keras.layers.Dense(7)) | |
model.compile( | |
optimizer='adam', | |
loss=tf.keras.losses.SparseCategoricalCrossentropy(from_logits=True), | |
metrics=['accuracy']) |
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
import dgl | |
import tensorflow as tf | |
dataset = dgl.data.CoraGraphDataset() | |
# A DGL dataset may contain multiple graphs. | |
# In the case of Cora, there is only one graph. | |
g = dataset[0] | |
# g.ndata is a dictionary of nodes related data. |
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
import tensorflow_data_validation as tfdv | |
from tensorflow_metadata.proto.v0 import anomalies_pb2 | |
stats = tfdv.load_stats_binary(GCS_PATH_FOR_STATS_PB) | |
tfdv.visualize_statistics(stats) | |
# Display output in screenshot later. | |
schema = tfdv.load_schema_text(GCS_PATH_FOR_SCHEMA_PBTXT) | |
tfdv.display_schema(schema) | |
# Display output in screenshot later. |
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
import tensorflow as tf | |
def normalize(image, label): | |
return tf.cast(image, dtype=tf.float32) / 255.0, label | |
train = ds['train'].map(normalize).batch(32) | |
test = ds['test'].map(normalize).batch(32) | |
encoding_model = tf.keras.Model(inputs=model.input, outputs=model.get_layer('flatten').output) |
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
import tensorflow as tf | |
# Load the saved custom model. | |
model = tf.keras.models.load_model(GCS_PATH_FOR_SAVED_MODEL) | |
model.compile(optimizer='adam', | |
loss=tf.keras.losses.SparseCategoricalCrossentropy(from_logits=False), | |
metrics=['accuracy']) | |
model.summary() | |
''' |
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
import numpy as np | |
from sklearn import decomposition | |
# Reuse the same ds from Tensorflow Dataset | |
train_data = list(ds['train'].map(lambda x, y: tf.reshape(x, [-1]))) | |
test_data = list(ds['test'].map(lambda x, y: tf.reshape(x, [-1]))) | |
X = tf.concat([train_data, test_data], 0).numpy() | |
print(np.shape(X)) | |
# Output: (60000, 3072) |
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
SELECT | |
# Display all metrics. | |
* | |
FROM | |
ML.EVALUATE( | |
MODEL `bqml.e2e-tutorial`, | |
( | |
SELECT | |
int64_field_0 as label, | |
* EXCEPT (int64_field_0) |
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
CREATE MODEL | |
# Name of the model. | |
`bqml.e2e-tutorial` | |
OPTIONS | |
# BigQuery will detect that it's for multiclass. | |
( MODEL_TYPE='LOGISTIC_REG') AS | |
SELECT | |
# Use the first column as the label. | |
int64_field_0 as label, | |
# The rest are features. |
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
SELECT * FROM `bqml.train` LIMIT 10; |