AI-For-Beginners/translations/ta/examples/03-image-classifier.ipynb

397 lines
19 KiB
Plaintext

{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# எளிய பட வகைப்பாளர்\n",
"\n",
"இந்த நோட்புக் ஒரு முன்பே பயிற்சி பெற்ற நரம்பியல் வலைப்பின்னலின் உதவியுடன் படங்களை வகைப்படுத்துவது எப்படி என்பதை காட்டுகிறது.\n",
"\n",
"**நீங்கள் கற்றுக்கொள்ளப்போகிறீர்கள்:**\n",
"- முன்பே பயிற்சி பெற்ற மாதிரியை ஏற்றுவது மற்றும் பயன்படுத்துவது\n",
"- பட முன்னேற்பாடு\n",
"- படங்களில் கணிப்புகளை செய்வது\n",
"- நம்பகத்தன்மை மதிப்பீடுகளை புரிந்துகொள்வது\n",
"\n",
"**பயன்பாட்டு வழக்கு:** படங்களில் பொருட்களை அடையாளம் காணுதல் (உதாரணமாக \"பூனை\", \"நாய்\", \"கார்\" போன்றவை) \n",
"\n",
"---\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## படி 1: தேவையான நூலகங்களை இறக்குமதி செய்யவும்\n",
"\n",
"நமக்கு தேவையான கருவிகளை இறக்குமதி செய்வோம். இவை அனைத்தையும் இன்னும் புரிந்துகொள்ளவில்லை என்றால் கவலைப்பட வேண்டாம்!\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Core libraries\n",
"import numpy as np\n",
"from PIL import Image\n",
"import requests\n",
"from io import BytesIO\n",
"\n",
"# TensorFlow for deep learning\n",
"try:\n",
" import tensorflow as tf\n",
" from tensorflow.keras.applications import MobileNetV2\n",
" from tensorflow.keras.applications.mobilenet_v2 import preprocess_input, decode_predictions\n",
" print(\"✅ TensorFlow loaded successfully!\")\n",
" print(f\" Version: {tf.__version__}\")\n",
"except ImportError:\n",
" print(\"❌ Please install TensorFlow: pip install tensorflow\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## படி 2: முன்பே பயிற்சி பெற்ற மாடலை ஏற்றவும்\n",
"\n",
"நாம் **MobileNetV2**-ஐ பயன்படுத்தப் போகிறோம், இது ஏற்கனவே மில்லியன் கணக்கான படங்களின் மீது பயிற்சி பெற்ற நரம்பியல் வலைப்பின்னல்.\n",
"\n",
"இதற்கு **Transfer Learning** என்று அழைக்கப்படுகிறது - மற்றொருவர் பயிற்சி செய்த மாடலை பயன்படுத்துவது!\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"print(\"📦 Loading pre-trained MobileNetV2 model...\")\n",
"print(\" This may take a minute on first run (downloading weights)...\")\n",
"\n",
"# Load the model\n",
"# include_top=True means we use the classification layer\n",
"# weights='imagenet' means it was trained on ImageNet dataset\n",
"model = MobileNetV2(weights='imagenet', include_top=True)\n",
"\n",
"print(\"✅ Model loaded!\")\n",
"print(f\" The model can recognize 1000 different object categories\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## படி 3: உதவியாளர் செயல்பாடுகள்\n",
"\n",
"நாம் உருவாக்கும் மாதிரிக்கு படங்களை ஏற்றவும் தயாரிக்கவும் உதவியாளர் செயல்பாடுகளை உருவாக்குவோம்.\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"def load_image_from_url(url):\n",
" \"\"\"\n",
" Load an image from a URL.\n",
" \n",
" Args:\n",
" url: Web address of the image\n",
" \n",
" Returns:\n",
" PIL Image object\n",
" \"\"\"\n",
" response = requests.get(url)\n",
" img = Image.open(BytesIO(response.content))\n",
" return img\n",
"\n",
"\n",
"def prepare_image(img):\n",
" \"\"\"\n",
" Prepare an image for the model.\n",
" \n",
" Steps:\n",
" 1. Resize to 224x224 (model's expected size)\n",
" 2. Convert to array\n",
" 3. Add batch dimension\n",
" 4. Preprocess for MobileNetV2\n",
" \n",
" Args:\n",
" img: PIL Image\n",
" \n",
" Returns:\n",
" Preprocessed image array\n",
" \"\"\"\n",
" # Resize to 224x224 pixels\n",
" img = img.resize((224, 224))\n",
" \n",
" # Convert to numpy array\n",
" img_array = np.array(img)\n",
" \n",
" # Add batch dimension (model expects multiple images)\n",
" img_array = np.expand_dims(img_array, axis=0)\n",
" \n",
" # Preprocess for MobileNetV2\n",
" img_array = preprocess_input(img_array)\n",
" \n",
" return img_array\n",
"\n",
"\n",
"def classify_image(img):\n",
" \"\"\"\n",
" Classify an image and return top predictions.\n",
" \n",
" Args:\n",
" img: PIL Image\n",
" \n",
" Returns:\n",
" List of (class_name, confidence) tuples\n",
" \"\"\"\n",
" # Prepare the image\n",
" img_array = prepare_image(img)\n",
" \n",
" # Make prediction\n",
" predictions = model.predict(img_array, verbose=0)\n",
" \n",
" # Decode predictions to human-readable labels\n",
" # top=5 means we get the top 5 most likely classes\n",
" decoded = decode_predictions(predictions, top=5)[0]\n",
" \n",
" # Convert to simpler format\n",
" results = [(label, float(confidence)) for (_, label, confidence) in decoded]\n",
" \n",
" return results\n",
"\n",
"\n",
"print(\"✅ Helper functions ready!\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## படி 4: மாதிரி படங்களில் சோதனை செய்யுங்கள்\n",
"\n",
"இணையத்தில் இருந்து சில படங்களை வகைப்படுத்த முயற்சிப்போம்!\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Sample images to classify\n",
"# These are from Unsplash (free stock photos)\n",
"test_images = [\n",
" {\n",
" \"url\": \"https://images.unsplash.com/photo-1514888286974-6c03e2ca1dba?w=400\",\n",
" \"description\": \"A cat\"\n",
" },\n",
" {\n",
" \"url\": \"https://images.unsplash.com/photo-1552053831-71594a27632d?w=400\",\n",
" \"description\": \"A dog\"\n",
" },\n",
" {\n",
" \"url\": \"https://images.unsplash.com/photo-1511919884226-fd3cad34687c?w=400\",\n",
" \"description\": \"A car\"\n",
" },\n",
"]\n",
"\n",
"print(f\"🧪 Testing on {len(test_images)} images...\")\n",
"print(\"=\" * 70)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### ஒவ்வொரு படத்தையும் வகைப்படுத்தவும்\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"for i, img_data in enumerate(test_images, 1):\n",
" print(f\"\\n📸 Image {i}: {img_data['description']}\")\n",
" print(\"-\" * 70)\n",
" \n",
" try:\n",
" # Load image\n",
" img = load_image_from_url(img_data['url'])\n",
" \n",
" # Display image\n",
" display(img.resize((200, 200))) # Show smaller version\n",
" \n",
" # Classify\n",
" results = classify_image(img)\n",
" \n",
" # Show predictions\n",
" print(\"\\n🎯 Top 5 Predictions:\")\n",
" for rank, (label, confidence) in enumerate(results, 1):\n",
" # Create a visual bar\n",
" bar_length = int(confidence * 50)\n",
" bar = \"█\" * bar_length\n",
" \n",
" print(f\" {rank}. {label:20s} {confidence*100:5.2f}% {bar}\")\n",
" \n",
" except Exception as e:\n",
" print(f\"❌ Error: {e}\")\n",
"\n",
"print(\"\\n\" + \"=\" * 70)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## படி 5: உங்கள் சொந்த படங்களை முயற்சிக்கவும்!\n",
"\n",
"கீழே உள்ள URL ஐ மாற்றி, நீங்கள் வகைப்படுத்த விரும்பும் எந்த பட URL ஐ வேண்டுமானாலும் பயன்படுத்துங்கள்.\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Try your own image!\n",
"# Replace this URL with any image URL\n",
"custom_image_url = \"https://images.unsplash.com/photo-1472491235688-bdc81a63246e?w=400\" # A flower\n",
"\n",
"print(\"🖼️ Classifying your custom image...\")\n",
"print(\"=\" * 70)\n",
"\n",
"try:\n",
" # Load and show image\n",
" img = load_image_from_url(custom_image_url)\n",
" display(img.resize((300, 300)))\n",
" \n",
" # Classify\n",
" results = classify_image(img)\n",
" \n",
" # Show results\n",
" print(\"\\n🎯 Top 5 Predictions:\")\n",
" print(\"-\" * 70)\n",
" for rank, (label, confidence) in enumerate(results, 1):\n",
" bar_length = int(confidence * 50)\n",
" bar = \"█\" * bar_length\n",
" print(f\" {rank}. {label:20s} {confidence*100:5.2f}% {bar}\")\n",
" \n",
" # Highlight top prediction\n",
" top_label, top_confidence = results[0]\n",
" print(\"\\n\" + \"=\" * 70)\n",
" print(f\"\\n🏆 Best guess: {top_label} ({top_confidence*100:.2f}% confident)\")\n",
" \n",
"except Exception as e:\n",
" print(f\"❌ Error: {e}\")\n",
" print(\" Make sure the URL points to a valid image!\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 💡 என்ன நடந்தது?\n",
"\n",
"1. **நாம் முன்பே பயிற்சி பெற்ற மாடலை ஏற்றினோம்** - MobileNetV2 மில்லியன் கணக்கான படங்களில் பயிற்சி பெற்றது \n",
"2. **நாம் படங்களை முன் செயலாக்கினோம்** - மாடலுக்காக அவற்றை அளவிடவும் வடிவமைக்கவும் செய்தோம் \n",
"3. **மாடல் கணிப்புகளை செய்தது** - 1000 பொருள் வகைகளுக்கான சாத்தியக்கூறுகளை வெளியிட்டது \n",
"4. **நாம் முடிவுகளை டிகோட் செய்தோம்** - எண்களை மனிதர்களுக்குப் புரியக்கூடிய லேபிள்களாக மாற்றினோம் \n",
"\n",
"### நம்பகத்தன்மை மதிப்பீடுகளைப் புரிந்துகொள்வது\n",
"\n",
"- **90-100%**: மிகவும் நம்பகமானது (கிட்டத்தட்ட சரியாக இருக்கும்) \n",
"- **70-90%**: நம்பகமானது (சரியாக இருக்க வாய்ப்பு உள்ளது) \n",
"- **50-70%**: சில அளவுக்கு நம்பகமானது (சரியாக இருக்கலாம்) \n",
"- **50% க்கும் குறைவாக**: அதிக நம்பகத்தன்மை இல்லை (சந்தேகமாக உள்ளது) \n",
"\n",
"### ஏன் கணிப்புகள் தவறாக இருக்கலாம்?\n",
"\n",
"- **அசாதாரண கோணம் அல்லது ஒளி** - மாடல் சாதாரண புகைப்படங்களில் பயிற்சி பெற்றது \n",
"- **பல பொருட்கள்** - மாடல் ஒரு முக்கிய பொருளை எதிர்பார்க்கிறது \n",
"- **அரிதான பொருட்கள்** - மாடல் 1000 வகைகளை மட்டுமே அறிகிறது \n",
"- **குறைந்த தரமான படம்** - மங்கலான அல்லது பிக்சலேட்டான படங்கள் கடினமாக இருக்கும் \n",
"\n",
"--- \n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 🚀 அடுத்த படிகள்\n",
"\n",
"1. **வித்தியாசமான படங்களை முயற்சிக்கவும்:**\n",
" - [Unsplash](https://unsplash.com) இல் படங்களை தேடுங்கள்\n",
" - வலது கிளிக் → \"Copy image address\" செய்து URL ஐ பெறுங்கள்\n",
"\n",
"2. **சோதனை செய்யுங்கள்:**\n",
" - கலைப்படைப்புகளை பயன்படுத்தினால் என்ன நடக்கிறது?\n",
" - வெவ்வேறு கோணங்களில் பொருட்களை அடையாளம் காண முடியுமா?\n",
" - பல பொருட்களை ஒரே நேரத்தில் எப்படி கையாளுகிறது?\n",
"\n",
"3. **மேலும் கற்றுக்கொள்ளுங்கள்:**\n",
" - [கம்ப்யூட்டர் விஷன் பாடங்களை](../lessons/4-ComputerVision/README.md) ஆராயுங்கள்\n",
" - உங்கள் சொந்த பட வகைப்பாளியை பயிற்சி செய்ய கற்றுக்கொள்ளுங்கள்\n",
" - CNNs (Convolutional Neural Networks) எப்படி வேலை செய்கின்றன என்பதை புரிந்துகொள்ளுங்கள்\n",
"\n",
"---\n",
"\n",
"## 🎉 வாழ்த்துக்கள்!\n",
"\n",
"நீங்கள் ஒரு முன்னணி நரம்பியல் வலைப்பின்னலின் உதவியுடன் ஒரு பட வகைப்பாளியை உருவாக்கியுள்ளீர்கள்!\n",
"\n",
"இந்தzelfde தொழில்நுட்பம் பின்வரும் செயல்பாடுகளுக்கு சக்தி அளிக்கிறது:\n",
"- Google Photos (உங்கள் புகைப்படங்களை ஒழுங்குபடுத்துதல்)\n",
"- சுய இயக்க வாகனங்கள் (பொருட்களை அடையாளம் காணுதல்)\n",
"- மருத்துவ பரிசோதனை (X-rays பகுப்பாய்வு)\n",
"- தரக் கட்டுப்பாடு (குறைபாடுகளை கண்டறிதல்)\n",
"\n",
"தொடர்ந்து ஆராய்ந்து கற்றுக்கொள்ளுங்கள்! 🚀\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n---\n\n**குறிப்பு**: \nஇந்த ஆவணம் [Co-op Translator](https://github.com/Azure/co-op-translator) என்ற AI மொழிபெயர்ப்பு சேவையைப் பயன்படுத்தி மொழிபெயர்க்கப்பட்டுள்ளது. நாங்கள் துல்லியத்திற்காக முயற்சிக்கின்றோம், ஆனால் தானியக்க மொழிபெயர்ப்புகளில் பிழைகள் அல்லது தவறான தகவல்கள் இருக்கக்கூடும் என்பதை கவனத்தில் கொள்ளவும். அதன் தாய்மொழியில் உள்ள மூல ஆவணம் அதிகாரப்பூர்வ ஆதாரமாக கருதப்பட வேண்டும். முக்கியமான தகவல்களுக்கு, தொழில்முறை மனித மொழிபெயர்ப்பு பரிந்துரைக்கப்படுகிறது. இந்த மொழிபெயர்ப்பைப் பயன்படுத்துவதால் ஏற்படும் எந்த தவறான புரிதல்கள் அல்லது தவறான விளக்கங்களுக்கு நாங்கள் பொறுப்பல்ல.\n"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.0"
},
"coopTranslator": {
"original_hash": "1d472141d9df46b751542b3c29f88677",
"translation_date": "2025-10-11T11:53:10+00:00",
"source_file": "examples/03-image-classifier.ipynb",
"language_code": "ta"
}
},
"nbformat": 4,
"nbformat_minor": 4
}