Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

copy_of_experiment_tracking_session.py 4.1 KB

You have to be logged in to leave a comment. Sign In
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
  1. # -*- coding: utf-8 -*-
  2. """Copy of Experiment Tracking Session.ipynb
  3. Automatically generated by Colaboratory.
  4. Original file is located at
  5. https://colab.research.google.com/drive/1Rw0_Y3JfbUwjbGnqQOzdQ3gAw8v0Pe63
  6. # Change the Runtime to GPU
  7. On the top nav-bar, choose `Runtme`, click on `change runtime type`, and under `Hardware accelerator` choose GPU.
  8. # Create a Repository on DAGsHub 🏗
  9. - We will start by [creating a new repository](https://dagshub.com/repo/create) on DAGsHub.
  10. <center>
  11. <img src="https://dagshub.com/nirbarazida/images/raw/22ffadf74508f2f8626a528ea55f0fbf3d43f941/colab-mlflow/create-a-repo.png" height="700"/>
  12. </center>
  13. <center><b>Congratulations</b> - you created your first DAGsHub repository! 🥳 </center>
  14. # Configure MLflow 🧐
  15. """
  16. """# Model 🪐"""
  17. import tensorflow as tf
  18. import IPython
  19. import numpy as np
  20. import matplotlib.pyplot as plt
  21. from sklearn.model_selection import train_test_split
  22. import os
  23. from getpass import getpass
  24. !pip install mlflow --quiet
  25. """**Initialize MLflow**"""
  26. import mlflow
  27. DAGSHUB_TOKEN = getpass('Enter your DAGsHub access token or password: ')
  28. os.environ['MLFLOW_TRACKING_USERNAME'] = USER_NAME
  29. os.environ['MLFLOW_TRACKING_PASSWORD'] = DAGSHUB_TOKEN
  30. mlflow.set_tracking_uri('https://dagshub.com/anupampatil44/1stondagshub.mlflow')
  31. mlflow.tensorflow.autolog()
  32. mlflow.log_param("task",2) #manual logging
  33. import requests
  34. from getpass import getpass
  35. import datetime
  36. """**Set Environment Variables**
  37. """
  38. #@title Enter the repository name for the project:
  39. REPO_NAME= "1stondagshub" #@param {type:"string"}
  40. #@title Enter the repository name for the project:
  41. REPO_OWNER= "anupampatil44" #@param {type:"string"}
  42. #@title Enter the username of your DAGsHub account:
  43. USER_NAME = "anupampatil44" #@param {type:"string"}
  44. """## Import the Data Files
  45. ![](https://camo.githubusercontent.com/01c057a753e92a9bc70b8c45d62b295431851c09cffadf53106fc0aea7e2843f/687474703a2f2f692e7974696d672e636f6d2f76692f3051493378675875422d512f687164656661756c742e6a7067)
  46. """
  47. mnist = tf.keras.datasets.mnist
  48. (X_train, y_train), (X_test, y_test) = mnist.load_data()
  49. X_train, X_test = X_train / 255.0, X_test / 255.0
  50. image = np.reshape(X_train[1], [28, 28])
  51. image_array = np.asarray(image)
  52. fig, ax = plt.subplots(figsize=(10, 15))
  53. img = ax.imshow(image_array, cmap='gray')
  54. for x in range(28):
  55. for y in range(28):
  56. value = round(image[y][x], 2)
  57. color = 'black' if value > 0.5 else 'white'
  58. ax.annotate(s=value, xy=(x, y), ha='center', va='center', color=color)
  59. """## Configure a Tensorflow Model"""
  60. batch_size = 32
  61. validation_split=0.2
  62. epochs=3
  63. optimizer='adam'
  64. metrics=['accuracy']
  65. model = tf.keras.models.Sequential([
  66. tf.keras.layers.Flatten(input_shape=(28, 28)),
  67. tf.keras.layers.Dense(128, activation='relu'),
  68. tf.keras.layers.Dropout(0.2),
  69. tf.keras.layers.Dense(10)
  70. ])
  71. loss_fn = tf.keras.losses.SparseCategoricalCrossentropy(from_logits=True)
  72. model.compile(optimizer=optimizer,
  73. loss=loss_fn,
  74. metrics=metrics)
  75. """## Train the Model"""
  76. model.fit(X_train, y_train, batch_size= batch_size,
  77. validation_split=validation_split, epochs=epochs,verbose=0)
  78. """# Finish Line 🏁
  79. **Congratulations** - You made it to the finish line! 🥳
  80. 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>
  81. More resources that can interest you:
  82. - [DAGsHub Docs](https://dagshub.com/docs/).
  83. - [Get Started Tutorial](https://dagshub.com/docs/getting-started/overview/).
  84. - [DAGsHub Blog](https://dagshub.com/blog/).
  85. - [FAQ](https://dagshub.com/docs/faq/).
  86. <br>
  87. 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!
  88. <br><br>
  89. """
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...