Computer Vision News - May 2023
13 Blood Cell Classification Using CV optimizer = Adam(lr=1e-4) model.compile(optimizer=optimizer, loss='categorical_crossentropy', metrics=['accuracy']) # Train the model batch_size = 8 epochs = 20 model.fit(X_train, y_train, batch_size=batch_size, epochs=epochs, validation_split=0.1) # Evaluate the model scores = model.evaluate(X_test, y_test) print("Test loss:", scores[0]) print("Test accuracy:", scores[1]) And for a final treat, what if we finetune our network?? Back to Tensorflow ResNet and I’ll leave the comparison to you as an exercise: import tensorflow as tf from tensorflow.keras import layers from tensorflow.keras.models import Model from tensorflow.keras.applications import ResNet50 from tensorflow.keras.optimizers import Adam from tensorflow.keras.preprocessing.image import ImageDataGenerator def build_resnet(input_shape, n_classes): inputs = tf.keras.Input(shape=input_shape) # Load pretrained ResNet model base_model = ResNet50(include_top=False, weights='imagenet', input_shape=input_shape) # Add custom layers x = base_model(inputs, training=False) x = layers.GlobalAveragePooling2D()(x) x = layers.Dense(256, activation='relu')(x) x = layers.Dropout(0.5)(x) outputs = layers.Dense(n_classes, activation='softmax')(x) # Build the model model = Model(inputs, outputs) return model # Load your dataset (X and y)
Made with FlippingBook
RkJQdWJsaXNoZXIy NTc3NzU=