Skip to content

Commit

Permalink
updates for lecture 2025
Browse files Browse the repository at this point in the history
  • Loading branch information
JonasFrey96 committed Feb 26, 2025
1 parent c4885ce commit af9d89b
Show file tree
Hide file tree
Showing 13 changed files with 762 additions and 12 deletions.
13 changes: 1 addition & 12 deletions .github/workflows/formatting.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,4 @@ jobs:
uses: lgeiger/black-action@master
with:
args: "--line-length 120 . --check"
name: black-action

auto-formatting:
name: runner / black
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Check files using the black formatter
uses: rickstaa/action-black@v1
id: action_black
with:
black_args: "--line-length 120 ."
name: black-action
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
scripts/wandb/*
scripts/images/*
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
308 changes: 308 additions & 0 deletions scripts/01_regression.ipynb

Large diffs are not rendered by default.

286 changes: 286 additions & 0 deletions scripts/02_classification.ipynb

Large diffs are not rendered by default.

165 changes: 165 additions & 0 deletions scripts/03_wandb.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Install and Import Required Libraries\n",
"Install wandb using pip and import the necessary libraries."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Import the necessary ibraries\n",
"import wandb\n",
"import numpy as np\n",
"import matplotlib.pyplot as plt\n",
"from PIL import Image\n",
"import os"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Initialize wandb Project\n",
"Initialize a new wandb project and configure the settings."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Initialize wandb Project\n",
"wandb.init(project=\"plr-exercise\", config={\n",
" \"learning_rate\": 0.001,\n",
" \"epochs\": 10,\n",
" \"batch_size\": 32\n",
"})\n",
"\n",
"# Access the configuration\n",
"config = wandb.config\n",
"\n",
"# Log the configuration\n",
"wandb.config.update({\n",
" \"optimizer\": \"adam\",\n",
" \"loss_function\": \"categorical_crossentropy\"\n",
"})"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Log Random Curves\n",
"Generate random curves and log them to wandb."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Generate random curves and log them to wandb\n",
"x = np.linspace(0, 10, 100)\n",
"y1 = np.sin(x) + np.random.normal(0, 0.1, 100)\n",
"y2 = np.cos(x) + np.random.normal(0, 0.1, 100)\n",
"\n",
"plt.figure()\n",
"plt.plot(x, y1, label='Random Sine Curve')\n",
"plt.plot(x, y2, label='Random Cosine Curve')\n",
"\n",
"plt.legend()\n",
"plt.title('Random Curves')\n",
"plt.xlabel('X-axis')\n",
"plt.ylabel('Y-axis')\n",
"\n",
"# Save the plot as an image file\n",
"plt.savefig('random_curves.png')\n",
"\n",
"# Log the plot image to wandb\n",
"wandb.log({\"random_curves\": wandb.Image('random_curves.png')})\n",
"\n",
"# Optionally, log the data points as well\n",
"wandb.log({\"x\": x, \"y1\": y1, \"y2\": y2})"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Upload Images of Dogs and Cats\n",
"Upload images of dogs and cats to wandb."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Upload Images of Dogs and Cats\n",
"\n",
"# Create a directory to store images\n",
"os.makedirs('images', exist_ok=True)\n",
"\n",
"# Download sample images of dogs and cats\n",
"!wget -O images/dog.jpg https://images.unsplash.com/photo-1560807707-8cc77767d783\n",
"!wget -O images/cat.jpg https://images.unsplash.com/photo-1518791841217-8f162f1e1131\n",
"\n",
"# Load the images using PIL\n",
"dog_image = Image.open('images/dog.jpg')\n",
"cat_image = Image.open('images/cat.jpg')\n",
"\n",
"# Log the images to wandb\n",
"wandb.log({\"dog_image\": wandb.Image(dog_image, caption=\"Dog\")})\n",
"wandb.log({\"cat_image\": wandb.Image(cat_image, caption=\"Cat\")})"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Create a new artifact\n",
"artifact = wandb.Artifact('source_code', type='code')\n",
"\n",
"# Add files to the artifact\n",
"artifact.add_file('./03_wandb.ipynb')\n",
"\n",
"# Log the artifact\n",
"wandb.log_artifact(artifact)\n",
"wandb.finish()\n"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.10"
}
},
"nbformat": 4,
"nbformat_minor": 2
}

0 comments on commit af9d89b

Please sign in to comment.