Chapter 6Artificial Intelligence~1 min read
Deep Learning — TensorFlow आणि PyTorch
Advanced Neural Networks
Deep Learning म्हणजे many layers असलेले neural networks — images, audio, text, video समजणे. Classical ML जिथे fail होतो (raw images, natural language) तिथे Deep Learning excellent results देतो.
TensorFlow vs PyTorch
- ▸TensorFlow (Google): Production deployment साठी excellent. Keras API — beginners साठी simple.
- ▸PyTorch (Meta): Research साठी most popular. Pythonic, flexible, easy to debug.
- ▸Beginners साठी: Keras (TensorFlow वर) — simplest API.
- ▸Research साठी: PyTorch — maximum flexibility.
Image Classification with Keras — MNIST digits
python
import tensorflow as tf
from tensorflow.keras import layers, models
import numpy as np
# MNIST dataset load — 28x28 handwritten digits
(X_train, y_train), (X_test, y_test) = tf.keras.datasets.mnist.load_data()
# Normalize — 0-255 → 0-1
X_train = X_train.astype('float32') / 255.0
X_test = X_test.astype('float32') / 255.0
# Flatten 28x28 → 784
X_train = X_train.reshape(-1, 784)
X_test = X_test.reshape(-1, 784)
# Model build करा
model = models.Sequential([
layers.Dense(256, activation='relu', input_shape=(784,)),
layers.Dropout(0.3), # Overfitting रोखतो
layers.Dense(128, activation='relu'),
layers.Dropout(0.3),
layers.Dense(10, activation='softmax') # 10 digits (0-9)
])
model.compile(
optimizer='adam',
loss='sparse_categorical_crossentropy',
metrics=['accuracy']
)
# Train करा
history = model.fit(
X_train, y_train,
epochs=10,
batch_size=128,
validation_split=0.1
)
# Evaluate
test_loss, test_acc = model.evaluate(X_test, y_test)
print(f"Test Accuracy: {test_acc:.2%}") # ~98%+CNN — Convolutional Neural Networks (Images साठी)
CNN for image classification
python
model = models.Sequential([
# Convolutional layers — image features extract करतात
layers.Conv2D(32, (3,3), activation='relu', input_shape=(28, 28, 1)),
layers.MaxPooling2D((2,2)), # Downsampling
layers.Conv2D(64, (3,3), activation='relu'),
layers.MaxPooling2D((2,2)),
layers.Flatten(),
layers.Dense(64, activation='relu'),
layers.Dense(10, activation='softmax')
])
# CNN: Dense NN पेक्षा images साठी खूप better — 99%+ accuracy on MNIST💡
Transfer Learning वापरा — ImageNet वर pre-trained models (ResNet, VGG, MobileNet) fine-tune करा. Scratch पासून train करणे expensive असते. Keras मध्ये `keras.applications.MobileNetV2()` directly available.
✅ Key Points — लक्षात ठेवा
- ▸Keras: beginner-friendly, TensorFlow वर
- ▸PyTorch: research-friendly, flexible
- ▸CNN: images साठी, RNN: sequences साठी
- ▸Dropout: overfitting रोखतो
- ▸Transfer Learning: pre-trained models fine-tune करा
0/11 chapters पूर्ण