پاییز ۱۴۰۲
This chapter covers:
How Computer see the above picture?
![]() |
-1 | 0 | +1 |
-1 | 0 | +1 |
-1 | 0 | +1 |
![]() |
||
![]() |
![]() |
![]() |
![]() |
![]() |
8.1 - Introduction to convnets
8.1 - Introduction to convnets
from tensorflow import keras
from tensorflow.keras import layers
model = keras.Sequential()
model.add(layers.Conv2D(32, (5, 5), activation='relu', input_shape=(28, 28, 1)))
model.add(layers.MaxPooling2D((2, 2)))
model.add(layers.Conv2D(64, (5, 5), activation='relu'))
model.add(layers.MaxPooling2D((2, 2)))
model.add(layers.Flatten())
model.add(layers.Dense(64, activation='relu'))
model.add(layers.Dense(10, activation='softmax'))
_________________________________________________________________ Layer (type) Output Shape Param # ================================================================= conv2d_6 (Conv2D) (None, 24, 24, 32) 832 max_pooling2d_2 (MaxPoolin (None, 12, 12, 32) 0 g2D) conv2d_7 (Conv2D) (None, 8, 8, 64) 51264 max_pooling2d_3 (MaxPoolin (None, 4, 4, 64) 0 g2D) flatten_2 (Flatten) (None, 1024) 0 dense_2 (Dense) (None, 64) 65600 dense_3 (Dense) (None, 10) 650 ================================================================= Total params: 118346 (462.29 KB) Trainable params: 118346 (462.29 KB) Non-trainable params: 0 (0.00 Byte) _________________________________________________________________
8.1 - Introduction to convnets
from tensorflow import keras
from tensorflow.keras import layers
inputs = keras.Input(shape=(28, 28, 1))
x = layers.Conv2D(filters=32, kernel_size=5, activation="relu")(inputs)
x = layers.MaxPooling2D(pool_size=2)(x)
x = layers.Conv2D(filters=64, kernel_size=5, activation="relu")(x)
x = layers.MaxPooling2D(pool_size=2)(x)
x = layers.Flatten()(x)
x = layers.Dense(64, activation="relu")(x)
outputs = layers.Dense(10, activation="softmax")(x)
model = keras.Model(inputs=inputs, outputs=outputs)
_________________________________________________________________ Layer (type) Output Shape Param # ================================================================= input_4 (InputLayer) [(None, 28, 28, 1)] 0 conv2d_10 (Conv2D) (None, 24, 24, 32) 832 max_pooling2d_6 (MaxPoolin (None, 12, 12, 32) 0 g2D) conv2d_11 (Conv2D) (None, 8, 8, 64) 51264 max_pooling2d_7 (MaxPoolin (None, 4, 4, 64) 0 g2D) flatten_4 (Flatten) (None, 1024) 0 dense_6 (Dense) (None, 64) 65600 dense_7 (Dense) (None, 10) 650 ================================================================= Total params: 118346 (462.29 KB) Trainable params: 118346 (462.29 KB) Non-trainable params: 0 (0.00 Byte) _________________________________________________________________
--
import keras
from keras import layers
from keras import models
model = models.Sequential()
model.add(layers.Conv2D(32, (3, 3), activation='relu', input_shape=(28, 28, 1)))
model.add(layers.MaxPooling2D((2, 2)))
model.add(layers.Conv2D(64, (3, 3), activation='relu'))
model.add(layers.MaxPooling2D((2, 2)))
model.add(layers.Conv2D(64, (3, 3), activation='relu'))
model.add(layers.Flatten())
model.add(layers.Dense(64, activation='relu'))
model.add(layers.Dense(10, activation='softmax'))
8.2 - Training a convnet from scratch on a small dataset
8.2 - Training a convnet from scratch on a small dataset
8.2 - Training a convnet from scratch on a small dataset
model = models.Sequential()
model.add(layers.Conv2D(32, (3, 3), activation='relu',
input_shape=(150, 150, 3)))
model.add(layers.MaxPooling2D((2, 2)))
model.add(layers.Conv2D(64, (3, 3), activation='relu'))
model.add(layers.MaxPooling2D((2, 2)))
model.add(layers.Conv2D(128, (3, 3), activation='relu'))
model.add(layers.MaxPooling2D((2, 2)))
model.add(layers.Conv2D(128, (3, 3), activation='relu'))
model.add(layers.MaxPooling2D((2, 2)))
model.add(layers.Flatten())
model.add(layers.Dense(512, activation='relu'))
model.add(layers.Dense(1, activation='sigmoid'))
webpage : http://mamintoosi.ir
webpage in github : http://mamintoosi.github.io
github : mamintoosi