This file contains 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 download_document(document_url: str) -> bytes: | |
"""Download a document from the given URL. | |
Args: | |
document_url (str): The URL of the document to download. | |
""" | |
import requests | |
import logging | |
logging.basicConfig(level=logging.INFO) |
This file contains 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 kfp import dsl, compiler, kubernetes | |
@dsl.component(packages_to_install=['requests']) | |
def download_document(document_url: str, document_path: str): | |
"""Download a document from the given URL. | |
Args: | |
document_url (str): The URL of the document to download. | |
document_path (str): The local path where the document will be saved. |
This file contains 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
strategy = tf.distribute.MirroredStrategy() | |
BATCH_SIZE = 64 | |
GLOBAL_BATCH_SIZE = BATCH_SIZE * strategy.num_replicas_in_sync | |
train_data = tf.data.Dataset(...).batch(GLOBAL_BATCH_SIZE) | |
with strategy.scope(): | |
model = tf.keras.Sequential(...) | |
model.compile(...) |
This file contains 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
BATCH_SIZE = 64 | |
train_data = tf.data.Dataset(...).batch(BATCH_SIZE) | |
model = tf.keras.Sequential(...) | |
model.compile(...) | |
model.fit(train_data, epochs=4) |
This file contains 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
class MyModel(keras.Model): | |
def train_step(self, data): | |
# Get the data batch | |
inputs, targets = data | |
# Get the model's weights | |
trainable_vars = self.trainable_variables | |
# Forward pass | |
with tf.GradientTape() as tape: | |
# Get the predictions | |
preds = self(inputs, training=True) |
This file contains 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 PIL import Image | |
from torchvision.prototype import models as pm | |
img = Image.open("test/assets/encode_jpeg/grace_hopper_517x606.jpg") | |
# Step 1: Load a pre-trained model. | |
# In this step we will load a ResNet architecture. | |
weights = pm.ResNet50_Weights.ImageNet1K_V1 | |
model = pm.resnet50(weights=weights) |
This file contains 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 torch | |
import torchvision.models as models | |
import torchvision.transforms as transforms | |
from PIL import Image | |
img = Image.open("test/assets/encode_jpeg/grace_hopper_517x606.jpg") | |
# Step 1: Load a pre-trained model. |
This file contains 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
imp = package.PackageImporter(path) | |
loaded_model = imp.load_pickle(package_name, resource_name) |
This file contains 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
with package.PackageExporter(path) as exp: | |
exp.extern("numpy.**") | |
exp.intern("models.**") | |
exp.save_pickle(package_name, resource_name, model) |
This file contains 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
with package.PackageExporter(path) as exp: | |
exp.intern("models.**") | |
exp.save_pickle(package_name, resource_name, model) |
NewerOlder