Spaces:
No application file
No application file
Create Em CPT
#1
by
emefeweb56
- opened
Em CPT
ADDED
@@ -0,0 +1,77 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
for _ in range(RUN_COUNT):
|
2 |
+
|
3 |
+
# 1️⃣ Initialize a new W&B run to track this job
|
4 |
+
run = wandb.init(project=PROJECT, config=set_config())
|
5 |
+
|
6 |
+
for epoch in range(5):
|
7 |
+
# 2️⃣ Log metrics to W&B for each epoch of training
|
8 |
+
run.log(get_metrics(epoch))
|
9 |
+
|
10 |
+
# 3️⃣ At the end of training, save the model artifact
|
11 |
+
# Name this artifact after the current run
|
12 |
+
model_artifact_name = "demo_model_" + run.id
|
13 |
+
# Create a new artifact
|
14 |
+
model = wandb.Artifact(model_artifact_name, type='model')
|
15 |
+
# Add files to the artifact, in this case a simple text file
|
16 |
+
model.add_file(get_model())
|
17 |
+
# Log the model to W&B
|
18 |
+
run.log_artifact(model)
|
19 |
+
|
20 |
+
# Call finish if you're in a notebook, to mark the run as done
|
21 |
+
run.finish()
|
22 |
+
|
23 |
+
|
24 |
+
|
25 |
+
https://colab.research.google.com/github/wandb/examples/blob/master/colabs/wandb-model-registry/W%26B_Model_Registry_Quickstart.ipynb#scrollTo=CFXVyKSaRtUw
|
26 |
+
|
27 |
+
#@title 1) Run this cell to set up `wandb` and define helper functions
|
28 |
+
|
29 |
+
|
30 |
+
# INSTALL W&B LIBRARY
|
31 |
+
!pip install wandb -qqq
|
32 |
+
|
33 |
+
import wandb
|
34 |
+
import os
|
35 |
+
import math
|
36 |
+
import random
|
37 |
+
|
38 |
+
# FORM VARIABLES
|
39 |
+
PROJECT = "Model_Registry_Quickstart" #@param {type:"string"}
|
40 |
+
RUN_COUNT = 3 #@param {type:"integer"}
|
41 |
+
|
42 |
+
|
43 |
+
# HELPER FUNCTIONS
|
44 |
+
# Create fake data to simulate training a model.
|
45 |
+
|
46 |
+
# Simulate setting up hyperparameters
|
47 |
+
# Return: A dict of params to log as config to W&B
|
48 |
+
def set_config():
|
49 |
+
config={
|
50 |
+
"learning_rate": 0.01 + 0.1 * random.random(),
|
51 |
+
"batch_size": 128,
|
52 |
+
"architecture": "CNN",
|
53 |
+
}
|
54 |
+
return config
|
55 |
+
|
56 |
+
# Simulate training a model
|
57 |
+
# Return: A model file to log as an artifact to W&B
|
58 |
+
def get_model():
|
59 |
+
file_name = "demo_model.h5"
|
60 |
+
model_file = open(file_name, 'w')
|
61 |
+
model_file.write('Imagine this is a big model file! ' + str(random.random()))
|
62 |
+
model_file.close()
|
63 |
+
return file_name
|
64 |
+
|
65 |
+
# Simulate logging metrics from model training
|
66 |
+
# Return: A dictionary of metrics to log to W&B
|
67 |
+
def get_metrics(epoch):
|
68 |
+
metrics = {
|
69 |
+
"acc": .8 + 0.04 * (math.log(1 + epoch + random.random()) + (0.3 * random.random())),
|
70 |
+
"val_acc": .75 + 0.04 * (math.log(1 + epoch + random.random()) - (0.3 * random.random())),
|
71 |
+
"loss": .1 + 0.1 * (4 - math.log(1 + epoch + random.random()) + (0.3 * random.random())),
|
72 |
+
"val_loss": .1 + 0.16 * (5 - math.log(1 + epoch + random.random()) - (0.3 * random.random())),
|
73 |
+
}
|
74 |
+
return metrics
|
75 |
+
|
76 |
+
run.id
|
77 |
+
saved_model_weights.pt
|