This file contains hidden or 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
| 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( |
This file contains hidden or 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
| 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([ |
This file contains hidden or 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
| 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)), |
This file contains hidden or 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
| # 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): |
This file contains hidden or 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
| 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 |
This file contains hidden or 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
| 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)), |
This file contains hidden or 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
| 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] |
This file contains hidden or 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
| 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) |
This file contains hidden or 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
| 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, |
This file contains hidden or 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
| 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) |
NewerOlder