Skip to content

Instantly share code, notes, and snippets.

View shettyvarshaa's full-sized avatar
:shipit:

Varshaa Shetty shettyvarshaa

:shipit:
View GitHub Profile
@shettyvarshaa
shettyvarshaa / P7.py
Created December 23, 2024 19:10
NN-LAB
import tensorflow as tf
from tensorflow.keras.applications import VGG16, VGG19
from tensorflow.keras import layers, models
import tensorflow_datasets as tfds
def preprocess_image(image, label):
image = tf.image.resize(image, (224, 224)) / 255.0
return image, tf.one_hot(label, depth=5)
(ds_train, ds_test), ds_info = tfds.load(
@shettyvarshaa
shettyvarshaa / P4.py
Created December 23, 2024 19:09
NN-LAB
import tensorflow as tf
from tensorflow.keras import layers, models
from tensorflow.keras.datasets import fashion_mnist
from tensorflow.keras.regularizers import l1, l2
(train_images, train_labels), (test_images, test_labels) = fashion_mnist.load_data()
train_images, test_images = train_images/ 255.0, test_images / 255.0
def build_and_evaluate(name, regularizer=None, dropout_rate=None):
model = models.Sequential([
@shettyvarshaa
shettyvarshaa / P1.py
Created December 16, 2024 20:29
NN-LAB
import numpy as np
import matplotlib.pyplot as plt
def softmax(x):
e_x = np.exp(x - np.max(x))
return e_x / np.sum(e_x, axis=0)
x = np.linspace(-10, 10, 400)
y = {
'sigmoid': 1 / (1 + np.exp(-x)),
@shettyvarshaa
shettyvarshaa / P2aP2b.py
Created December 16, 2024 20:28
NN-LAB
# 2a
import numpy as np
import matplotlib.pyplot as plt
from sklearn.datasets import make_blobs
from sklearn.linear_model import Perceptron
X, y = make_blobs(n_samples=100, centers=2, random_state=42)
model = Perceptron(max_iter=1000, eta0=0.01, random_state=42).fit(X, y)
def plot_decision_boundary(model, X, y):
@shettyvarshaa
shettyvarshaa / P3.py
Last active December 23, 2024 14:35
NN-LAB
import tensorflow as tf
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense, Flatten
from tensorflow.keras.utils import to_categorical
from tensorflow.keras.datasets import mnist
(x_train, y_train), (x_test, y_test) = mnist.load_data()
x_train, x_test = x_train / 255.0, x_test / 255.0
@shettyvarshaa
shettyvarshaa / P5.py
Created December 16, 2024 20:26
NN-LAB
import tensorflow as tf
from tensorflow.keras.datasets import mnist
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense, Flatten
(X_train, y_train), (X_test, y_test) = mnist.load_data()
X_train, X_test = X_train / 255.0, X_test / 255.0
model = Sequential([
Flatten(input_shape=(28, 28)),
@shettyvarshaa
shettyvarshaa / P6.py
Created December 16, 2024 20:26
NN-LAB
import tensorflow as tf
from tensorflow.keras.datasets import imdb
from tensorflow.keras.preprocessing.sequence import pad_sequences
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Embedding, LSTM, Dense, Bidirectional
(x_train, y_train), (x_test, y_test) = imdb.load_data(num_words=20000)
x_train, y_train = x_train[:5000], y_train[:5000]
x_test, y_test = x_test[:1000], y_test[:1000]
@shettyvarshaa
shettyvarshaa / P7.py
Created December 15, 2024 21:14
DIP-LAB
import cv2
import numpy as np
import matplotlib.pyplot as plt
def transform_image(image, tx, ty, angle, scale):
h, w = image.shape[:2]
translated = cv2.warpAffine(image, np.float32([[1, 0, tx], [0, 1,ty]]), (w, h))
rotation_matrix = cv2.getRotationMatrix2D((w // 2, h // 2), angle,1)
rotated = cv2.warpAffine(image, rotation_matrix, (w, h))
scaled = cv2.resize(image, None, fx=scale, fy=scale)
@shettyvarshaa
shettyvarshaa / P5.py
Created December 15, 2024 21:01
DIP-LAB
import cv2
import matplotlib.pyplot as plt
image = cv2.imread('./images/img1.png', cv2.IMREAD_GRAYSCALE)
kernel = cv2.getStructuringElement(cv2.MORPH_RECT, (5, 5))
eroded_image = cv2.erode(image, kernel)
erosion_diff = cv2.absdiff(image, eroded_image)
dilated_image = cv2.dilate(image, kernel)
dilation_diff = cv2.absdiff(image, dilated_image)
titles = ['Original', 'Eroded', 'Erosion Diff', 'Dilated', 'Dilation Diff']
images = [image, eroded_image, erosion_diff, dilated_image,
@shettyvarshaa
shettyvarshaa / P4.py
Created December 15, 2024 20:35
DIP-LAB
import cv2
import numpy as np
import matplotlib.pyplot as plt
image = cv2.imread('./images/img1.png')
gray_image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
kernel = np.ones((5, 5), np.float32) / 25
low_pass = cv2.filter2D(gray_image, -1, kernel)
high_pass = gray_image - low_pass
plt.figure(figsize=(15, 5))
plt.subplot(1, 3, 1)