1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
|
- # -*- coding: utf-8 -*-
- """Copy of Experiment Tracking Session.ipynb
- Automatically generated by Colaboratory.
- Original file is located at
- https://colab.research.google.com/drive/1Rw0_Y3JfbUwjbGnqQOzdQ3gAw8v0Pe63
- # Change the Runtime to GPU
- On the top nav-bar, choose `Runtme`, click on `change runtime type`, and under `Hardware accelerator` choose GPU.
- # Create a Repository on DAGsHub 🏗
- - We will start by [creating a new repository](https://dagshub.com/repo/create) on DAGsHub.
- <center>
- <img src="https://dagshub.com/nirbarazida/images/raw/22ffadf74508f2f8626a528ea55f0fbf3d43f941/colab-mlflow/create-a-repo.png" height="700"/>
- </center>
- <center><b>Congratulations</b> - you created your first DAGsHub repository! 🥳 </center>
- # Configure MLflow 🧐
- """
- """# Model 🪐"""
- import tensorflow as tf
- import IPython
- import numpy as np
- import matplotlib.pyplot as plt
- from sklearn.model_selection import train_test_split
- import os
- from getpass import getpass
- !pip install mlflow --quiet
- """**Initialize MLflow**"""
- import mlflow
- DAGSHUB_TOKEN = getpass('Enter your DAGsHub access token or password: ')
- os.environ['MLFLOW_TRACKING_USERNAME'] = USER_NAME
- os.environ['MLFLOW_TRACKING_PASSWORD'] = DAGSHUB_TOKEN
- mlflow.set_tracking_uri('https://dagshub.com/anupampatil44/1stondagshub.mlflow')
- mlflow.tensorflow.autolog()
- mlflow.log_param("task",2) #manual logging
- import requests
- from getpass import getpass
- import datetime
- """**Set Environment Variables**
- """
- #@title Enter the repository name for the project:
- REPO_NAME= "1stondagshub" #@param {type:"string"}
- #@title Enter the repository name for the project:
- REPO_OWNER= "anupampatil44" #@param {type:"string"}
- #@title Enter the username of your DAGsHub account:
- USER_NAME = "anupampatil44" #@param {type:"string"}
- """## Import the Data Files
- ![](https://camo.githubusercontent.com/01c057a753e92a9bc70b8c45d62b295431851c09cffadf53106fc0aea7e2843f/687474703a2f2f692e7974696d672e636f6d2f76692f3051493378675875422d512f687164656661756c742e6a7067)
- """
- mnist = tf.keras.datasets.mnist
- (X_train, y_train), (X_test, y_test) = mnist.load_data()
- X_train, X_test = X_train / 255.0, X_test / 255.0
- image = np.reshape(X_train[1], [28, 28])
- image_array = np.asarray(image)
- fig, ax = plt.subplots(figsize=(10, 15))
- img = ax.imshow(image_array, cmap='gray')
- for x in range(28):
- for y in range(28):
- value = round(image[y][x], 2)
- color = 'black' if value > 0.5 else 'white'
- ax.annotate(s=value, xy=(x, y), ha='center', va='center', color=color)
- """## Configure a Tensorflow Model"""
- batch_size = 32
- validation_split=0.2
- epochs=3
- optimizer='adam'
- metrics=['accuracy']
- model = tf.keras.models.Sequential([
- tf.keras.layers.Flatten(input_shape=(28, 28)),
- tf.keras.layers.Dense(128, activation='relu'),
- tf.keras.layers.Dropout(0.2),
- tf.keras.layers.Dense(10)
- ])
- loss_fn = tf.keras.losses.SparseCategoricalCrossentropy(from_logits=True)
- model.compile(optimizer=optimizer,
- loss=loss_fn,
- metrics=metrics)
- """## Train the Model"""
- model.fit(X_train, y_train, batch_size= batch_size,
- validation_split=validation_split, epochs=epochs,verbose=0)
- """# Finish Line 🏁
- **Congratulations** - You made it to the finish line! 🥳
- In this section, we covered how to track fast.ai models with MLflow to DAGsHub servers. If you want to start fast with DAGsHub, this [notebook](https://colab.research.google.com/drive/1JJIwAH0TBSY49um5s2FD0GEA6bw3SKrd#scrollTo=XcU2y1F_Hyub) is for you. <br><br>
- More resources that can interest you:
- - [DAGsHub Docs](https://dagshub.com/docs/).
- - [Get Started Tutorial](https://dagshub.com/docs/getting-started/overview/).
- - [DAGsHub Blog](https://dagshub.com/blog/).
- - [FAQ](https://dagshub.com/docs/faq/).
- <br>
- We hope that this Tutorial was helpful and made the onboarding process easier for you. If you found an issue in the notebook, please [let us know](https://dagshub.com/DAGsHub-Official/DAGsHub-Issues/issues/). If you have any questions feel free to join our [Discord channel](https://discord.com/invite/9gU36Y6) and ask there. We can't wait to see what remarkable project you will create and share with the Data Science community!
- <br><br>
- """
|