יסודות בינה מלאכותית : 04-RB29 – יסודות בינה מלאכותית
היום ננסה לבנות את היסדות של רשת ניירונים של בינה מלאוכתית שרואה
- מבוא לשפת פייתון – קולאב
1.1 פתח את הקולאב – https://colab.research.google.com/
חלק ג : מבוא לפייתון והרצה קוד של בינה מלאכותית :
- העשרה עבודה בקולאב
תרגיל כיתה 2
1.1 פתח את הקולאב – https://colab.research.google.com/
2. הרץ את התוכנית הבאה
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
import matplotlib.pyplot as plt # Data to plot x = [1, 2, 3, 4, 5] y = [2, 3, 5, 7, 11] # Create the plot plt.plot(x, y) # Add labels and title plt.xlabel('X axis') plt.ylabel('Y axis') plt.title('Simple Plot in Colab') # Display the plot plt.show() |
\
2.1
תרגיל כיתה 3
2.2 הרץ את התכונית הבאה בקולאב :
string
Python, strings are zero-indexed, which means the first character of a string is at index 0
, the second character is at index 1
, and so on
הדפסה של על התווים ניראה בהמשלך לולאות
כתיבה יותר מקוצרת אבל פחות " קלה "
Output: The word 'Python' is in the text!
1
2
3
4
5
6
|
text = "Learning Python is fun!"
if text.find("Python") != –1:
print("Found the word 'Python' in the text!")
else:
print("Couldn't find the word 'Python' in the text.")
|
3.LOOP FOR הרץ אאת התוכנית הבא : חשוב להבנה ל YOLO
1 2 3 4 5 6 |
# Define a list of objects results = ["car", "people", "truck", "bicycle", "motorcycle"] # Iterate over the list and print each object for result in results: print(result) |
3.2 לולאת FOR
1 2 3 4 5 6 7 |
# Define a list of objects results = ["car", "people", "truck", "bicycle", "motorcycle"] # Iterate over the list and print only if the object is "car" for result in results: if result == "car": print(result) |
תרגיל כיתה 4 – כתיבת קוד בינה מלאכותית בעזרת CHATGPT
4. בנה בעזרת בינה מלאכותית תוכנה בפייטון המציגה את הפונציה Y=2X^3 + 2 ואת הנגזרת שלה על גרף
4.1 הרץ את הקוד בקולאב
4.2 תיקון שגיאות בקוד תוכנה על ידי בינה מלאוכתית
4.3 הרץ את הקוד הבא בפייתון
4.4 הקלד את קדו ואת השגיעות לבינה מלאכותית ובקש ממנה לתקן
4.5 מה עושה הקוד ?
1 2 3 4 5 6 |
import random # Import the module that allows random number generation # Generate 5 random numbers between 1 and 10 and print them for i in range(5): random_number = rand-om.randint(1, 10) # Generate a random number between 1 and 10 prnt(f"Random number {i+1}: {random_number}") |
תרגיל כיתה 5 : שימוש פילטרים ועיבוד תמונה וראייה ממוחשבת
5.1 הרץ את התכונה
פילטר סיבולס
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 |
import cv2 import numpy as np import requests import matplotlib.pyplot as plt from PIL import Image from io import BytesIO # קישור התמונה image_url = "https://robotronix.co.il/wp-content/uploads/2024/09/image-65-300x81.png" # הורדת התמונה response = requests.get(image_url) image = Image.open(BytesIO(response.content)) # המרת התמונה למערך NumPy image_np = np.array(image) # המרת תמונה לגווני אפור gray = cv2.cvtColor(image_np, cv2.COLOR_RGB2GRAY) # יישום סיבול (סף בינארי) _, thresholded = cv2.threshold(gray, 127, 255, cv2.THRESH_BINARY) # הצגת התמונה המקורית והתוצאה plt.figure(figsize=(10,5)) plt.subplot(1,2,1) plt.imshow(image_np) plt.title("Original Image") plt.axis("off") plt.subplot(1,2,2) plt.imshow(thresholded, cmap='gray') plt.title("Thresholded Image") plt.axis("off") plt.show() |
5.2 פילטר טישטוש גאוסיאני
כולל מסנן גאוסי להורדת רעש לפני יישום פילטר Canny לזיהוי קצוות. כעת ניתן לראות את התמונה המקורית, את התמונה לאחר טשטוש גאוסי, ואת התמונה לאחר זיהוי קצוות עם Canny.
הפונקציה cv2.GaussianBlur(gray, (5, 5), 0)
מבצעת טשטוש גאוסי על התמונה בגווני אפור. נפרט על כל פרמטר:
gray
– התמונה בגווני אפור עליה מופעל הטשטוש.(5, 5)
– גודל המסנן (Kernel Size), כלומר חלון בגודל 5×5 פיקסלים בו מחושב הטשטוש. ערך גבוה יותר גורם לטשטוש חזק יותר.0
– סטיית התקן של הפילטר בציר ה-X וה-Y. כאשר הערך הוא0
, OpenCV מחשב את הסטיית התקן באופן אוטומטי בהתבסס על גודל המסנן.-
משמעות של ערכי סטיית התקן (
sigmaX
) בפונקציהcv2.GaussianBlur
הפרמטר השלישי בפונקציה
cv2.GaussianBlur(gray, (5, 5), 0)
הוא סטיית התקן של הפילטר בציר ה-X (sigmaX
). המשמעות של הערכים האפשריים:-
sigmaX = 0
(או לא מוגדר)- OpenCV מחשב באופן אוטומטי את סטיית התקן על בסיס גודל המסנן (
kernel size
). - התוצאה היא טשטוש מאוזן המתאים לגודל החלון שנבחר.
- OpenCV מחשב באופן אוטומטי את סטיית התקן על בסיס גודל המסנן (
-
sigmaX = 1
- מגדיר טשטוש קל יחסית עם השפעה מינימלית על התמונה.
- שימושי כשצריך להחליק וריאציות קטנות בלי לאבד יותר מדי פרטים.
-
sigmaX = -1
- ערך שלילי גורם ל-OpenCV להפעיל את אותה הלוגיקה כמו
sigmaX = 0
, כלומר חישוב אוטומטי על פי גודל המסנן.
- ערך שלילי גורם ל-OpenCV להפעיל את אותה הלוגיקה כמו
-
ערכים גבוהים של
sigmaX
(למשל 3, 5, 10)- גורמים לטשטוש חזק יותר ומחליקים קווים ורעשים משמעותיים בתמונה.
- ככל שהערך גבוה יותר, כך פרטים קטנים יותר נעלמים, והתמונה הופכת ליותר "מרוחה".
sigmaY
אם לא מציינים
sigmaY
, הוא יקבל כברירת מחדל את הערך שלsigmaX
. אם רוצים לטשטש בצורה שונה על ציר ה-X וה-Y, ניתן לצייןsigmaY
בנפרד. -
המטרה של הטשטוש הגאוסי היא להקטין רעשים לפני יישום פילטר Canny, מה שמשפר את זיהוי הקצוות בתמונה
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 |
import cv2 import numpy as np import requests import matplotlib.pyplot as plt from PIL import Image from io import BytesIO # קישור התמונה image_url = "https://robotronix.co.il/wp-content/uploads/2024/09/image-65-300x81.png" # הורדת התמונה response = requests.get(image_url) image = Image.open(BytesIO(response.content)) # המרת התמונה למערך NumPy image_np = np.array(image) # המרת תמונה לגווני אפור gray = cv2.cvtColor(image_np, cv2.COLOR_RGB2GRAY) # יישום מסנן גאוסי להורדת רעש gaussian_blur = cv2.GaussianBlur(gray, (5, 5), 0) # יישום פילטר Canny לזיהוי קצוות לאחר גאוסיאן edges = cv2.Canny(gaussian_blur, 100, 200) # הצגת התמונה המקורית והתוצאות plt.figure(figsize=(15,5)) plt.subplot(1,3,1) plt.imshow(image_np) plt.title("Original Image") plt.axis("off") plt.subplot(1,3,2) plt.imshow(gaussian_blur, cmap='gray') plt.title("Gaussian Blur") plt.axis("off") plt.subplot(1,3,3) plt.imshow(edges, cmap='gray') plt.title("Canny Edges after Gaussian Blur") plt.axis("off") plt.show() |
5.3 שאל את הבינה המלאכותית מהו פילטר קוני ואיך הוא עוזר ליבנה מלאוכתית
פילטר קוני
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 |
import cv2 import numpy as np import requests import matplotlib.pyplot as plt from PIL import Image from io import BytesIO # קישור התמונה image_url = "https://robotronix.co.il/wp-content/uploads/2024/09/image-65-300x81.png" # הורדת התמונה response = requests.get(image_url) image = Image.open(BytesIO(response.content)) # המרת התמונה למערך NumPy image_np = np.array(image) # המרת תמונה לגווני אפור gray = cv2.cvtColor(image_np, cv2.COLOR_RGB2GRAY) # יישום פילטר Canny edges = cv2.Canny(gray, 100, 200) # הצגת התמונה המקורית והתוצאה plt.figure(figsize=(10,5)) plt.subplot(1,2,1) plt.imshow(image_np) plt.title("Original Image") plt.axis("off") plt.subplot(1,2,2) plt.imshow(edges, cmap='gray') plt.title("Canny Edges") plt.axis("off") plt.show() |
קישור מסכם
https://colab.research.google.com/drive/1wwk-FqjQLT0d9Rl114jifz1_IKer2mN8#scrollTo=B6XiFturPMwD
6. זיהוי אובייקטים בעזרת תוכנה YOLO כתיבת
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 |
# Install YOLOv8 from Ultralytics !pip install ultralytics # Import necessary libraries from ultralytics import YOLO from PIL import Image import requests from io import BytesIO import matplotlib.pyplot as plt # Load pre-trained YOLOv8 model (YOLOv8s is small and fast) model = YOLO('yolov8s.pt') # yolov8s.pt is the small model trained on COCO dataset # Download the image from the provided URL img_url = 'https://robotronix.co.il/wp-content/uploads/2024/06/image-12.png' response = requests.get(img_url) img = Image.open(BytesIO(response.content)) # Perform detection on the image results = model(img) # Display the results (show detected objects on the image) # Use .plot() to visualize results for each result in the results list for result in results: result_img = result.plot() # This plots the detections on the image # Display the image with detections plt.imshow(result_img) plt.axis('off') # Hide axes plt.show() # Print the detection results (bounding boxes, labels, and confidence scores) print(results[0].boxes.xyxy) # Bounding box coordinates print(results[0].boxes.cls) # Class IDs print(results[0].boxes.conf) # Confidence scores |
5. כמה מכוניות יש בכביש
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 |
# Install YOLOv8 from Ultralytics !pip install ultralytics # Import necessary libraries from ultralytics import YOLO from PIL import Image import requests from io import BytesIO import matplotlib.pyplot as plt # Load pre-trained YOLOv8 model (YOLOv8s is small and fast) model = YOLO('yolov8s.pt') # yolov8s.pt is the small model trained on COCO dataset # Download the image from the provided URL img_url = 'https://robotronix.co.il/wp-content/uploads/2024/06/image-12.png' response = requests.get(img_url) img = Image.open(BytesIO(response.content)) # Perform detection on the image results = model(img) # Class names for the COCO dataset (80 classes) class_names = model.names # Count the number of cars detected (class id for 'car' is usually 2 in COCO) car_count = 0 for result in results: # Get the class IDs of detected objects detected_classes = result.boxes.cls # Count how many times 'car' (class ID 2) is detected car_count += int((detected_classes == 2).sum()) # Output the number of cars detected print(f"Number of cars detected: {car_count}") # Display the results (show detected objects on the image) for result in results: result_img = result.plot() # Plot detections on the image # Display the image with detections plt.imshow(result_img) plt.axis('off') # Hide axes plt.show() |
6.בדוק כמה מכוניות יש עבור התמונה הבאה :
7. שנה את הקוד בעזרת בינה מלאכותית שאם יש יותר מ 20 מוכניות הכביש עמוס , אם יש פחות הכביש פתוח
8 בנה תוכנה ב YOLO שבודקת מה יש בתמונה הבאה
10.השץמש ב CHAT GPT
4.1 לרחפן חילוץ נידרש תאורה או לטיסה בלילה בתוך מבנה לסריקה
במבנה לא קיים חשמל בכלל
4.1 העזר בבינה מלאכותית למציאת פתרון הבעיה
4.2 מה זה LUX בהקשר בתאורה
4.3 כמה LUX דרוש להאיר 3 מטר קדימה בחושך מלא עבור רחפן ואיזה זווית מומץ לעדשה
4.4 חפש ציוד מתאים באלי אקספרס העזר בבינה מלאכותית – שים לבלב שהרחפן מסוגל לשאת עד 0.2 ק"ג כלומר 200 גרם
canva
תרגיל כיתה 1 – הפקת סירטוני אנימציה ב CANVA
- צור בעזרת תוכנת CANVA אנימציה
- העזר בסרטון הדרכ שהוא 3 דקות + , שלב אחרי שלב
תרגיל כיתה 2 – הפקת סירטוני אנימציה ב CANVA
העשרה :
פילטר Canny הוא אלגוריתם לעיבוד תמונה המשמש לגילוי קצוות בתמונה. הוא פועל בשלבים ברורים על מנת להוציא את הקווים החדים והמשמעותיים בתמונה. הנה ההסבר שלב אחרי שלב:
שלב 1: המרת התמונה לגווני אפור
תמונות צבעוניות מכילות הרבה מידע, ולכן הצעד הראשון הוא להמיר אותן לשחור-לבן (גווני אפור). זה מקל על עיבוד הנתונים ומאפשר להתמקד בעוצמות האור ולא בצבעים.
שלב 2: טשטוש התמונה בעזרת מסנן גאוסי
לפני שמחפשים קצוות, מרככים את התמונה כדי להוריד רעש. רעש עלול לגרום לאלגוריתם לזהות קווים מיותרים. משתמשים במסנן גאוסי, שהוא דרך מתמטית להחליק את התמונה.
שלב 3: חישוב שיפועי בהירות
בשלב זה, האלגוריתם מחשב את ההבדלים בעוצמת התאורה של כל נקודה בתמונה. אם יש שינוי חד בעוצמת התאורה (לדוגמה, מעבר מאזור בהיר לאזור כהה), זה סימן שיש שם קצה.
שלב 4: דיכוי לא מקסימלי
השלב הזה מסנן החוצה קווים מטושטשים ומשאיר רק את הקווים החדים ביותר. כל פיקסל בתמונה נבדק, ורק הנקודות עם ההפרש הגדול ביותר בעוצמת התאורה נשמרות.
שלב 5: סף היסטרזיס
לבסוף, מוחלט אילו קצוות לשמור על פי ערכי סף שנקבעים מראש. אם הבדל התאורה חזק במיוחד, הוא נשמר כקצה ברור. אם הוא חלש מאוד, הוא נמחק. אם הוא בינוני, נבדק האם הוא מחובר לקצה חזק כדי להחליט אם לשמור אותו.
התוצאה הסופית היא תמונה שבה נראים רק הקווים החדים והמשמעותיים ביותר, מה שמקל על זיהוי עצמים וצורות בתמונה.
העשרה : מערכות ימיות אוטונומיות