Created
July 3, 2019 08:37
-
-
Save yongjun823/82aba27b85c94246918f6d3981a22599 to your computer and use it in GitHub Desktop.
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 Flatten, Dense, Conv2D | |
from tensorflow.keras.preprocessing.image import ImageDataGenerator | |
train_datagen = ImageDataGenerator( | |
rescale=1./255, | |
validation_split=0.15 | |
) | |
train_generator = train_datagen.flow_from_directory( | |
'../../Downloads/sss', | |
target_size=(24, 24), | |
batch_size=2, | |
class_mode='binary') | |
for r in train_generator: | |
print(r[0].shape, r[1].shape) | |
print(r[0].dtype, r[1].dtype) | |
break | |
data_generator = tf.data.Dataset.from_generator(lambda: train_generator, | |
output_types=(tf.float32, tf.float32), | |
output_shapes=((2, 24, 24, 3), (2, ))) | |
model = Sequential([ | |
Conv2D(10, (3, 3), activation='relu', input_shape=(24, 24, 3)), | |
Flatten(), | |
Dense(1, activation='sigmoid') | |
]) | |
model.summary() | |
model.compile(optimizer='adam', loss='binary_crossentropy', metrics=['accuracy']) | |
model.fit(data_generator, epochs=10, steps_per_epoch=1) | |
# model.fit_generator( | |
# train_generator, | |
# steps_per_epoch=10, | |
# epochs=5 | |
# ) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment