<jupyter_start><jupyter_text>Malaria Classification TF 2.0<jupyter_code>import numpy as np
import tensorflow 
print('Tensorflow version',tensorflow.__version__)

import matplotlib.pyplot as plt

from tensorflow.keras.preprocessing.image import ImageDataGenerator
from tensorflow.keras import layers, models

import os
print(os.listdir("./cell_images"))
import split_folders
orig_path = './cell_images'
output_path = '../output'
split_folders.ratio(orig_path, output=output_path, seed=1, ratio=(.8, .2))
data_dir = '../output'
train = data_dir+'/train/'
test = data_dir+'/val/'
train_image_gen = ImageDataGenerator(rotation_range=30,
                               width_shift_range=0.1,
                               height_shift_range=0.1,
                               rescale=1./255,
                               shear_range=0.1,
                               zoom_range=0.1,
                               horizontal_flip=True,
                               fill_mode='nearest')

test_image_gen = ImageDataGenerator(rescale=1./255)
'''Set the CNN model'''
image_shape = (130,130, 3)
model = models.Sequential()

model.add(layers.Conv2D(32, (3, 3), activation='relu', input_shape=image_shape))
model.add(layers.MaxPooling2D((2, 2)))
model.add(layers.Dropout(0.25))
          
model.add(layers.Conv2D(64, (3, 3), activation='relu'))
model.add(layers.MaxPooling2D((2, 2)))
model.add(layers.Dropout(0.25))

model.add(layers.Conv2D(64, (3, 3), activation='relu'))
model.add(layers.MaxPooling2D((2, 2)))
model.add(layers.Dropout(0.25))

          
model.add(layers.Flatten())
model.add(layers.Dense(128, activation='relu'))
model.add(layers.Dropout(0.5))
model.add(layers.Dense(1, activation='sigmoid'))

model.compile(optimizer='adam',
              loss='binary_crossentropy',
              metrics=['accuracy'])
model.summary()
from tensorflow.keras.callbacks import EarlyStopping

early_stop = EarlyStopping(monitor='val_loss',patience=2)
batch_size = 16

train_generator = train_image_gen.flow_from_directory(train,
                                                      target_size=image_shape[:2],
                                                      color_mode='rgb',
                                                      batch_size=batch_size,
                                                      class_mode='binary')

test_generator = test_image_gen.flow_from_directory(test,
                                                    target_size=image_shape[:2],
                                                    color_mode='rgb',
                                                    batch_size=batch_size,
                                                    class_mode='binary',
                                                    shuffle=False)
history = model.fit_generator(train_generator, epochs=20,
                              validation_data = test_generator,
                              callbacks=[early_stop])
model.save('./malaria_model')<jupyter_output>INFO:tensorflow:Assets written to: ./malaria_model\assets
{'fraction_non_alphanumeric': 0.11202635914332784, 'fraction_numerical': 0.025041186161449753, 'mean_word_length': 1.9361702127659575, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 18, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '516088', 'license': 'MIT', 'n_tokens_mistral': 863, 'n_tokens_neox': 827, 'n_words': 127, 'path': 'notebooks/tf-malaria-training.ipynb', 'repo_name': 'alexandergg/Inference-Optimizations', 'size': '3035'}