1+ {
2+ "nbformat" : 4 ,
3+ "nbformat_minor" : 0 ,
4+ "metadata" : {
5+ "colab" : {
6+ "provenance" : [],
7+ "authorship_tag" : " ABX9TyP/ew1Uv62mJHN1xFzV2pd8" ,
8+ "include_colab_link" : true
9+ },
10+ "kernelspec" : {
11+ "name" : " python3" ,
12+ "display_name" : " Python 3"
13+ },
14+ "language_info" : {
15+ "name" : " python"
16+ },
17+ "accelerator" : " GPU" ,
18+ "gpuClass" : " standard"
19+ },
20+ "cells" : [
21+ {
22+ "cell_type" : " markdown" ,
23+ "metadata" : {
24+ "id" : " view-in-github" ,
25+ "colab_type" : " text"
26+ },
27+ "source" : [
28+ " <a href=\" https://colab.research.google.com/github/duchaba/Data-Augmentation-with-Python/blob/main/data_augmentation_with_python_chapter_1.ipynb\" target=\" _parent\" ><img src=\" https://colab.research.google.com/assets/colab-badge.svg\" alt=\" Open In Colab\" /></a>"
29+ ]
30+ },
31+ {
32+ "cell_type" : " markdown" ,
33+ "source" : [
34+ " # Data Augmentation with Python, Chapter 1"
35+ ],
36+ "metadata" : {
37+ "id" : " qtnHR_uG0m7Z"
38+ }
39+ },
40+ {
41+ "cell_type" : " markdown" ,
42+ "source" : [
43+ " ## 🌻 Welcome to Chapter 1, section Programing Style and Pluto\n " ,
44+ " \n " ,
45+ " - GitHub access \n " ,
46+ " \n " ,
47+ " - Object-Oriented \n " ,
48+ " \n " ,
49+ " - Full library variable name \n " ,
50+ " \n " ,
51+ " - Export to pure Python code \n " ,
52+ " \n " ,
53+ " - Coding companion "
54+ ],
55+ "metadata" : {
56+ "id" : " a5EqgaYW08Cm"
57+ }
58+ },
59+ {
60+ "cell_type" : " markdown" ,
61+ "source" : [
62+ " ## GitHub Access (from Collab)"
63+ ],
64+ "metadata" : {
65+ "id" : " 0Mo-idJS3eDh"
66+ }
67+ },
68+ {
69+ "cell_type" : " markdown" ,
70+ "source" : [
71+ " 1. From the Colab menu, click on \" File\"\n " ,
72+ " \n " ,
73+ " 1. Select \" Open Notebook\"\n " ,
74+ " \n " ,
75+ " 1. Click on \" GitHub\" tab\n " ,
76+ " \n " ,
77+ " 1. Enter \" https://github.com/PacktPublishing/data-augmentation-with-python\" in the \" Repository\" field. \n " ,
78+ " \n " ,
79+ " 1. You should see all Notebooks available."
80+ ],
81+ "metadata" : {
82+ "id" : " hJ6ydtag4Nvc"
83+ }
84+ },
85+ {
86+ "cell_type" : " markdown" ,
87+ "source" : [
88+ " ## Object-Oriented"
89+ ],
90+ "metadata" : {
91+ "id" : " ukspBUMp4N97"
92+ }
93+ },
94+ {
95+ "cell_type" : " code" ,
96+ "source" : [
97+ " # git version should be 2.17.1 or higher\n " ,
98+ " !git --version"
99+ ],
100+ "metadata" : {
101+ "id" : " AEoYuTg6y1YN"
102+ },
103+ "execution_count" : null ,
104+ "outputs" : []
105+ },
106+ {
107+ "cell_type" : " code" ,
108+ "source" : [
109+ " # url = 'https://github.com/duchaba/Data-Augmentation-with-Python' # for testing: remove after the book is finished.\n " ,
110+ " \n " ,
111+ " url = 'https://github.com/PacktPublishing/Data-Augmentation-with-Python'\n " ,
112+ " !git clone {url}"
113+ ],
114+ "metadata" : {
115+ "id" : " BgGgEP3SytI4"
116+ },
117+ "execution_count" : null ,
118+ "outputs" : []
119+ },
120+ {
121+ "cell_type" : " code" ,
122+ "source" : [
123+ " pluto_chapter_1 = '/content/Data-Augmentation-with-Python/pluto/pluto_chapter_1.py'"
124+ ],
125+ "metadata" : {
126+ "id" : " pibFWfy-0w5z"
127+ },
128+ "execution_count" : null ,
129+ "outputs" : []
130+ },
131+ {
132+ "cell_type" : " code" ,
133+ "execution_count" : null ,
134+ "metadata" : {
135+ "id" : " F7hGhKAE0bmh"
136+ },
137+ "outputs" : [],
138+ "source" : [
139+ " # %%writefile {pluto_chapter_1}\n " ,
140+ " \n " ,
141+ " # create an object\n " ,
142+ " # First, importing the basic library\n " ,
143+ " import torch\n " ,
144+ " import pandas\n " ,
145+ " import numpy\n " ,
146+ " import matplotlib\n " ,
147+ " import pathlib\n " ,
148+ " import PIL\n " ,
149+ " import datetime\n " ,
150+ " import sys\n " ,
151+ " import psutil\n " ,
152+ " # create class/object \n " ,
153+ " class PacktDataAug(object):\n " ,
154+ " #\n " ,
155+ " # initialize the object\n " ,
156+ " def __init__(self, name=\" Pluto\" , is_verbose=True,*args, **kwargs):\n " ,
157+ " super(PacktDataAug, self).__init__(*args, **kwargs)\n " ,
158+ " self.author = \" Duc Haba\"\n " ,
159+ " self.version = 1.0\n " ,
160+ " self.name = name\n " ,
161+ " if (is_verbose):\n " ,
162+ " self._ph()\n " ,
163+ " self._pp(\" Hello from class\" , f\" {self.__class__} Class: {self.__class__.__name__}\" )\n " ,
164+ " self._pp(\" Code name\" , self.name)\n " ,
165+ " self._pp(\" Author is\" , self.author)\n " ,
166+ " self._ph()\n " ,
167+ " #\n " ,
168+ " return\n " ,
169+ " #\n " ,
170+ " # pretty print output name-value line\n " ,
171+ " def _pp(self, a, b):\n " ,
172+ " print(\" %28s : %s\" % (str(a), str(b)))\n " ,
173+ " return\n " ,
174+ " #\n " ,
175+ " # pretty print the header or footer lines\n " ,
176+ " def _ph(self):\n " ,
177+ " print(\" -\" * 28, \" :\" , \" -\" * 28)\n " ,
178+ " return\n " ,
179+ " # ---end of class\n " ,
180+ " #\n " ,
181+ " # Hack it! Add new decorator\n " ,
182+ " # add_method() is inspired Michael Garod's blog, \n " ,
183+ " # AND correction by: Филя Усков\n " ,
184+ " #\n " ,
185+ " import functools\n " ,
186+ " def add_method(x):\n " ,
187+ " def dec(z):\n " ,
188+ " @functools.wraps(z) \n " ,
189+ " def y(*args, **kwargs): \n " ,
190+ " return z(*args, **kwargs)\n " ,
191+ " setattr(x, z.__name__, y)\n " ,
192+ " return z \n " ,
193+ " return dec\n " ,
194+ " #"
195+ ]
196+ },
197+ {
198+ "cell_type" : " markdown" ,
199+ "source" : [
200+ " - Instantiate your [pluto] coding companion."
201+ ],
202+ "metadata" : {
203+ "id" : " tibZw65iC9lx"
204+ }
205+ },
206+ {
207+ "cell_type" : " code" ,
208+ "source" : [
209+ " # %%writefile -a {pluto_chapter_1}\n " ,
210+ " \n " ,
211+ " pluto = PacktDataAug(\" Pluto\" )"
212+ ],
213+ "metadata" : {
214+ "id" : " rtOsxJVNC8AV"
215+ },
216+ "execution_count" : null ,
217+ "outputs" : []
218+ },
219+ {
220+ "cell_type" : " code" ,
221+ "source" : [
222+ " # %%writefile -a {pluto_chapter_1}\n " ,
223+ " \n " ,
224+ " @add_method(PacktDataAug)\n " ,
225+ " def say_sys_info(self):\n " ,
226+ " self._ph()\n " ,
227+ " now = datetime.datetime.now()\n " ,
228+ " self._pp(\" System time\" , now.strftime(\" %Y/%m/%d %H:%M\" ))\n " ,
229+ " self._pp(\" Platform\" , sys.platform)\n " ,
230+ " self._pp(\" Pluto Version (Chapter)\" , self.version)\n " ,
231+ " v = sys.version.replace('\\ n', '')\n " ,
232+ " self._pp(\" Python (3.7.10)\" , f'actual: {v}')\n " ,
233+ " self._pp(\" PyTorch (1.11.0)\" , f'actual: {torch.__version__}')\n " ,
234+ " self._pp(\" Pandas (1.3.5)\" , f'actual: {pandas.__version__}')\n " ,
235+ " self._pp(\" PIL (9.0.0)\" , f'actual: {PIL.__version__}')\n " ,
236+ " self._pp(\" Matplotlib (3.2.2)\" , f'actual: {matplotlib.__version__}')\n " ,
237+ " #\n " ,
238+ " try:\n " ,
239+ " val = psutil.cpu_count()\n " ,
240+ " self._pp(\" CPU count\" , val)\n " ,
241+ " val = psutil.cpu_freq()\n " ,
242+ " if (None != val):\n " ,
243+ " val = val._asdict()\n " ,
244+ " self._pp(\" CPU speed\" , f'{val[\" current\" ]/1000:.2f} GHz')\n " ,
245+ " self._pp(\" CPU max speed\" , f'{val[\" max\" ]/1000:.2f} GHz') \n " ,
246+ " else:\n " ,
247+ " self._pp(\" *CPU speed\" , \" NOT available\" )\n " ,
248+ " except:\n " ,
249+ " pass\n " ,
250+ " self._ph()\n " ,
251+ " return"
252+ ],
253+ "metadata" : {
254+ "id" : " eaYZdpesv7_V"
255+ },
256+ "execution_count" : null ,
257+ "outputs" : []
258+ },
259+ {
260+ "cell_type" : " code" ,
261+ "source" : [
262+ " pluto.say_sys_info()"
263+ ],
264+ "metadata" : {
265+ "id" : " ZeTJo-9-Lrv1"
266+ },
267+ "execution_count" : null ,
268+ "outputs" : []
269+ },
270+ {
271+ "cell_type" : " code" ,
272+ "source" : [
273+ " # end of chapter 1"
274+ ],
275+ "metadata" : {
276+ "id" : " FWpmCx6sJiFg"
277+ },
278+ "execution_count" : null ,
279+ "outputs" : []
280+ },
281+ {
282+ "cell_type" : " markdown" ,
283+ "source" : [
284+ " ## Export to pure Python code (Optional)"
285+ ],
286+ "metadata" : {
287+ "id" : " 9t1NqPdsR6kS"
288+ }
289+ },
290+ {
291+ "cell_type" : " markdown" ,
292+ "source" : [
293+ " - Add the \" %%writefile your_file_name.py\" to the first code cell that you want export\n " ,
294+ " \n " ,
295+ " - Add the \" %%writefile -a your_file_name.py\" (-a is for append) to the code cells that you want to export.\n " ,
296+ " \n " ,
297+ " - Make it a comment when you using the code cells normally.\n " ,
298+ " \n " ,
299+ " - Uncommend the \" %%writefile\" and run each code cells to export the file."
300+ ],
301+ "metadata" : {
302+ "id" : " ajnizD18R6vm"
303+ }
304+ },
305+ {
306+ "cell_type" : " markdown" ,
307+ "source" : [
308+ " ## Push up all changes (Optional)"
309+ ],
310+ "metadata" : {
311+ "id" : " LEj7fgaIN9_S"
312+ }
313+ },
314+ {
315+ "cell_type" : " markdown" ,
316+ "source" : [
317+ " - username: [your github username or email]\n " ,
318+ " \n " ,
319+ " - password: [use github token]"
320+ ],
321+ "metadata" : {
322+ "id" : " lHXRf21BT9N8"
323+ }
324+ },
325+ {
326+ "cell_type" : " code" ,
327+ "source" : [
328+ " # import os\n " ,
329+ " # f = 'Data-Augmentation-with-Python'\n " ,
330+ " # os.chdir(f)\n " ,
331+ " # !git add -A\n " ,
332+ " # !git config --global user.email \" duc.haba@gmail.com\"\n " ,
333+ " # !git config --global user.name \" duchaba\"\n " ,
334+ " # !git commit -m \" end of session\"\n "
335+ ],
336+ "metadata" : {
337+ "id" : " eSXJKJFlOEeE"
338+ },
339+ "execution_count" : null ,
340+ "outputs" : []
341+ },
342+ {
343+ "cell_type" : " code" ,
344+ "source" : [
345+ " # end of chapter 1\n " ,
346+ " print('End of chapter 1')"
347+ ],
348+ "metadata" : {
349+ "id" : " zeFM8XUHc1c7"
350+ },
351+ "execution_count" : null ,
352+ "outputs" : []
353+ },
354+ {
355+ "cell_type" : " markdown" ,
356+ "source" : [
357+ " ## Summary"
358+ ],
359+ "metadata" : {
360+ "id" : " EzO7lDYDWeLz"
361+ }
362+ },
363+ {
364+ "cell_type" : " markdown" ,
365+ "source" : [
366+ " Every chaper will begin with same base class \" PacktDataAug\" .\n " ,
367+ " \n " ,
368+ " ✋ FAIR WARNING:\n " ,
369+ " \n " ,
370+ " - The coding uses long and complete function path name.\n " ,
371+ " \n " ,
372+ " - I wrote the code for easy to understand and not for compactness, fast execution, nor cleaverness.\n " ,
373+ " \n "
374+ ],
375+ "metadata" : {
376+ "id" : " X2iUPf3EWePd"
377+ }
378+ },
379+ {
380+ "cell_type" : " code" ,
381+ "source" : [
382+ " # # do the git push in the xterm console\n " ,
383+ " # #!git push\n " ,
384+ " \n " ,
385+ " # !pip install colab-xterm\n " ,
386+ " # %load_ext colabxterm\n " ,
387+ " # %xterm"
388+ ],
389+ "metadata" : {
390+ "id" : " s2MlGMMzz4mS"
391+ },
392+ "execution_count" : null ,
393+ "outputs" : []
394+ }
395+ ]
396+ }
0 commit comments