Last active
May 19, 2020 22:26
-
-
Save awah95/8446f11ec4b3cae42d0a0e150b02ec2e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# coding: utf-8 | |
# مرحب بيكم معانا. هنا الكود الكتبناو مع بعض في الفيديو في قناة البعد الخامس | |
# Import the libraries (ادخال المكتبات المهمه للبرنامج حقنا) | |
import matplotlib.pyplot as plt | |
import numpy as np | |
import mnist | |
from keras.models import Sequential | |
from keras.layers import Dense | |
from keras.utils import to_categorical | |
# فصل صور التدريب و الصور الحنمتحن بيها البرنامج حقنا | |
train_images = mnist.train_images() | |
train_labels = mnist.train_labels() | |
test_images = mnist.test_images() | |
test_labels = mnist.test_labels() | |
# هنا حنشوف وحده من الصور | |
# غير ال 0 لا رقم بين صفر و ٦٠٠٠٠ | |
train_images[0] | |
# الجزو ده بيرسم لينا الصوره رقم ١ او بالاصح العندها اندكس صفر | |
# looking at the picture with index 0 :) | |
fig = plt.figure | |
plt.imshow(train_images[0], cmap='gray') | |
plt.show() | |
# هنا حنتاكد من انو فعلاالاجابه حقة الصوره صفر هي الانحن شفناها | |
train_labels[0] | |
# هنا حنعمل النورمالايزيشن | |
# Normalization | |
# اللهو حنخلي الصوره بين -٠.٥ و +٠.٥ | |
# +0.5 & -0.5 | |
train_images = (train_images / 255) - 0.5 | |
test_images = (test_images / 255) - 0.5 | |
# هنا حنشوف شكل الصوره بعد عملنا النورمالايزيشن بقت كيف | |
train_images[0] | |
#هنا بنعدل الاريي حقتنا تكون افقيه و اري وحده | |
#الشكل الاول كان ٢٨ في ٢٨ | |
# هسه حنخليها ٧٨٤ | |
train_images = train_images.reshape((-1, 784)) | |
test_images = test_images.reshape((-1, 784)) | |
# هنا حنشوف بس شكلها بقي كيف عشان دي حاجه كوول و دارين نجر بيكم هوا ساي :) | |
train_images[0] | |
# هنا بنعمل المودل حقنا | |
model = Sequential([ | |
Dense(64, activation='relu', input_shape=(784,)), | |
Dense(64, activation='relu'), | |
Dense(10, activation='softmax'), | |
]) | |
# هنا بنعمل كومبايل | |
model.compile( | |
optimizer='adam', | |
loss='categorical_crossentropy', | |
metrics=['accuracy'], | |
) | |
# هنا بندري البرنامج العملناو ونخليو يتعلم | |
# لو داير تشغل البرنامج ده براك جرب تربع الايبيكس لي ١٠ حتشوفو بقي ازكي :) | |
# What I just said is increase the epochs to 10! our little AI will get smarter :D | |
model.fit( | |
train_images, | |
to_categorical(train_labels), | |
epochs=5, | |
batch_size=32, | |
) | |
# هنا بنمتحن فيو | |
model.evaluate( | |
test_images, | |
to_categorical(test_labels) | |
) | |
# هنا بنشوف هل هو فعلا اتعلم ولا لا | |
predictions = model.predict(test_images[:5]) | |
print(np.argmax(predictions, axis=1)) | |
print(test_labels[:5]) | |
# متزكر قبيل غيرنا الصوره لي ٧٨٤ بدل ٢٨ في ٢٨؟ هسه محتاجين نرجعه عشان بس نتاكد انو اجابت الزكاء حقنا شغاله | |
test_images = mnist.test_images() | |
# و هنا بنرسم بس عادي | |
fig = plt.figure | |
plt.imshow(test_images[4], cmap='gray') | |
plt.show() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
apt-get update | |
apt-get upgrade | |
apt install python3-pip python3-dev libatlas-base-dev | |
pip3 install virtualenv numpy pandas Scikit-learn | |
pip3 install --user --upgrade tensorflow # install in $HOME | |
pip3 install keras jupyter matplotlib | |
jupyter notebook --allow-root | |
# SSH tunnel to port 8888 | |
# ssh -i KEY.PEM -L 8888:localhost:8888 root@IP.Adress.Here | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment