working version 1.0
Browse files- .gitignore +2 -0
- app.py +55 -2
- requirements.txt +2 -0
- utils.py +29 -0
.gitignore
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
wandb/
|
2 |
+
__pycache__/
|
app.py
CHANGED
@@ -1,4 +1,57 @@
|
|
|
|
|
|
1 |
import streamlit as st
|
|
|
2 |
|
3 |
-
|
4 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import wandb
|
3 |
import streamlit as st
|
4 |
+
import streamlit.components.v1 as components
|
5 |
|
6 |
+
from utils import train
|
7 |
+
|
8 |
+
project = "st"
|
9 |
+
entity = "capecape"
|
10 |
+
|
11 |
+
HEIGHT = 720
|
12 |
+
|
13 |
+
def get_project(api, name, entity=None):
|
14 |
+
return api.project(name, entity=entity).to_html(height=HEIGHT)
|
15 |
+
|
16 |
+
st.title("Let's log some metrics to wandb 👇")
|
17 |
+
|
18 |
+
# Sidebar
|
19 |
+
sb = st.sidebar
|
20 |
+
sb.title("Train your model")
|
21 |
+
# wandb_token = sb.text_input("paste your wandb Api key if you want: https://wandb.ai/authorize", type="password")
|
22 |
+
|
23 |
+
|
24 |
+
# wandb.login(key=wandb_token)
|
25 |
+
wandb.login(anonymous="allow")
|
26 |
+
api = wandb.Api()
|
27 |
+
|
28 |
+
# render wandb dashboard
|
29 |
+
components.html(get_project(api, project, entity), height=HEIGHT)
|
30 |
+
|
31 |
+
# run params
|
32 |
+
runs = sb.number_input('Number of runs:', min_value=1, max_value=10, value=1)
|
33 |
+
epochs = sb.number_input('Number of epochs:', min_value=1, max_value=1000, value=100)
|
34 |
+
|
35 |
+
|
36 |
+
|
37 |
+
pseudo_code = """
|
38 |
+
We will execute a simple training loop
|
39 |
+
```python
|
40 |
+
wandb.init(project="st", ...)
|
41 |
+
for i in range(epochs):
|
42 |
+
acc = 1 - 2 ** -i - random()
|
43 |
+
loss = 2 ** -i + random()
|
44 |
+
wandb.log({"acc": acc,
|
45 |
+
"loss": loss})
|
46 |
+
```
|
47 |
+
"""
|
48 |
+
|
49 |
+
sb.write(pseudo_code)
|
50 |
+
|
51 |
+
# train model
|
52 |
+
if sb.button("Run Example"):
|
53 |
+
my_bar = sb.progress(0)
|
54 |
+
print("Running training")
|
55 |
+
for i in range(runs):
|
56 |
+
train(project=project, entity=entity, epochs=epochs)
|
57 |
+
my_bar.progress((i+1)/runs)
|
requirements.txt
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
wandb
|
2 |
+
streamlit
|
utils.py
ADDED
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import random, time
|
2 |
+
|
3 |
+
import wandb
|
4 |
+
|
5 |
+
|
6 |
+
def train(project="st", entity=None, epochs=10):
|
7 |
+
run = wandb.init(
|
8 |
+
# Set the project where this run will be logged
|
9 |
+
project=project,
|
10 |
+
entity=entity,
|
11 |
+
# Track hyperparameters and run metadata
|
12 |
+
config={
|
13 |
+
"learning_rate": 0.02,
|
14 |
+
"architecture": "CNN",
|
15 |
+
"dataset": "CIFAR-100",
|
16 |
+
"epochs": epochs,
|
17 |
+
})
|
18 |
+
|
19 |
+
# This simple block simulates a training loop logging metrics
|
20 |
+
offset = random.random() / 5
|
21 |
+
for epoch in range(1, epochs+1):
|
22 |
+
acc = 1 - 2 ** -epoch - random.random() / epoch - offset
|
23 |
+
loss = 2 ** -epoch + random.random() / epoch + offset
|
24 |
+
# 2️⃣ Log metrics from your script to W&B
|
25 |
+
wandb.log({"acc": acc, "loss": loss})
|
26 |
+
time.sleep(0.1)
|
27 |
+
|
28 |
+
# Mark the run as finished
|
29 |
+
wandb.finish()
|