Spaces:
Running
Running
Commit
·
5974209
1
Parent(s):
97ea680
Update utils.py
Browse files
utils.py
CHANGED
|
@@ -1,24 +1,3 @@
|
|
| 1 |
-
from tensorflow.keras.models import Sequential
|
| 2 |
-
from tensorflow.keras.layers import Conv2D, Flatten, MaxPooling2D, Dense, Dropout, SpatialDropout2D
|
| 3 |
-
from tensorflow.keras.losses import sparse_categorical_crossentropy, binary_crossentropy
|
| 4 |
-
from tensorflow.keras.optimizers import Adam
|
| 5 |
-
from tensorflow.keras.preprocessing.image import ImageDataGenerator
|
| 6 |
-
import numpy as np
|
| 7 |
-
from PIL import Image
|
| 8 |
-
|
| 9 |
-
def gen_labels():
|
| 10 |
-
train = 'Dataset/Train'
|
| 11 |
-
train_generator = ImageDataGenerator(rescale = 1/255)
|
| 12 |
-
|
| 13 |
-
train_generator = train_generator.flow_from_directory(train,
|
| 14 |
-
target_size = (300,300),
|
| 15 |
-
batch_size = 32,
|
| 16 |
-
class_mode = 'sparse')
|
| 17 |
-
labels = (train_generator.class_indices)
|
| 18 |
-
labels = dict((v,k) for k,v in labels.items())
|
| 19 |
-
|
| 20 |
-
return labels
|
| 21 |
-
|
| 22 |
def preprocess(image):
|
| 23 |
image = np.array(image.resize((256, 256), Image.LANCZOS))
|
| 24 |
image = np.array(image, dtype='uint8')
|
|
@@ -30,7 +9,7 @@ def model_arc():
|
|
| 30 |
model = Sequential()
|
| 31 |
|
| 32 |
# Convolution blocks
|
| 33 |
-
model.add(Conv2D(32, kernel_size=(3,3), padding='same', input_shape=(
|
| 34 |
model.add(MaxPooling2D(pool_size=2))
|
| 35 |
|
| 36 |
model.add(Conv2D(64, kernel_size=(3,3), padding='same', activation='relu'))
|
|
@@ -49,4 +28,4 @@ def model_arc():
|
|
| 49 |
model.add(Dropout(0.2))
|
| 50 |
model.add(Dense(6, activation='softmax'))
|
| 51 |
|
| 52 |
-
return model
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
def preprocess(image):
|
| 2 |
image = np.array(image.resize((256, 256), Image.LANCZOS))
|
| 3 |
image = np.array(image, dtype='uint8')
|
|
|
|
| 9 |
model = Sequential()
|
| 10 |
|
| 11 |
# Convolution blocks
|
| 12 |
+
model.add(Conv2D(32, kernel_size=(3,3), padding='same', input_shape=(256, 256, 3), activation='relu'))
|
| 13 |
model.add(MaxPooling2D(pool_size=2))
|
| 14 |
|
| 15 |
model.add(Conv2D(64, kernel_size=(3,3), padding='same', activation='relu'))
|
|
|
|
| 28 |
model.add(Dropout(0.2))
|
| 29 |
model.add(Dense(6, activation='softmax'))
|
| 30 |
|
| 31 |
+
return model
|