Skip to content

Instantly share code, notes, and snippets.

View dpoulopoulos's full-sized avatar
Work from home

Dimitris Poulopoulos dpoulopoulos

Work from home
View GitHub Profile
@dpoulopoulos
dpoulopoulos / Snakefile
Created April 15, 2025 08:21
Document-to-Podcase Snakemake adaptation
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)
@dpoulopoulos
dpoulopoulos / pipeline.py
Created April 11, 2025 08:02
document_to_podcast_kfp.py
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.
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(...)
BATCH_SIZE = 64
train_data = tf.data.Dataset(...).batch(BATCH_SIZE)
model = tf.keras.Sequential(...)
model.compile(...)
model.fit(train_data, epochs=4)
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)
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)
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.
imp = package.PackageImporter(path)
loaded_model = imp.load_pickle(package_name, resource_name)
with package.PackageExporter(path) as exp:
exp.extern("numpy.**")
exp.intern("models.**")
exp.save_pickle(package_name, resource_name, model)
with package.PackageExporter(path) as exp:
exp.intern("models.**")
exp.save_pickle(package_name, resource_name, model)