Image classification for projects and researches

Overview

Python 3.7 Python 3.8 MIT License Coverage

KERAS CLASSIFY

Image classification for projects and researches

About The Project

Image classification is a commonly used problem in the experimental part of scientific papers and also frequently appears as part of the projects. With the desire to reduce time and effort, Keras Classify was created.

Getting Started

Installation

  1. Clone the repo: https://github.com/nguyentruonglau/keras-classify.git

  2. Install packages

    > python -m venv 
         
          
    > activate.bat (in scripts folder)
    > pip install -r requirements.txt
    
         

Todo List:

  • Cosine learning rate scheduler
  • Gradient-based Localization
  • Sota models
  • Synthetic data
  • Smart Resize
  • Support Python 3.X and Tf 2.X
  • Use imagaug for augmentation data
  • Use prefetching and multiprocessing to training.
  • Analysis Of Input Shape
  • Compiled using XLA, auto-clustering on GPU
  • Receiver operating characteristic

Quick Start

Analysis Of Input Shape

If your data has random input_shape, you don't know which input_shape to choose, the analysis program is the right choice for you. The algorithm is applied to analyze: Kernel Density Estimation.

Convert Data

From tensorflow 2.3.x already support auto fit_generator, however moving the data to npy file will make it easier to manage. The algorithm is applied to shuffle data: Random Permutation. Read more here.

Run: python convert/convert_npy.py

Training Model.

Design your model at model/models.py, we have made EfficientNetB0 the default. Adjust the appropriate hyperparameters and run: python train.py

Evaluate Model.

  • Statistics number of images per class after suffle on test data.

  • Provide model evalution indicators such as: Accuracy, Precesion, Recall, F1-Score and AUC (Area Under the Curve).

  • Plot training history of Accuracy, Loss, Receiver Operating Characteristic curve and Confusion Matrix.

Explainable AI.

Grad-CAM: Visual Explanations from Deep Networks via Gradient-based Localization. "We propose a technique for producing 'visual explanations' for decisions from a large class of CNN-based models, making them more transparent" Ramprasaath R. Selvaraju ... Read more here.

Example Code

Use for projects

from keras.preprocessing.image import load_img, img_to_array
from keras.preprocessing.image import smart_resize
from tensorflow.keras.models import load_model
import tensorflow as tf
import numpy as np

#load pretrained model
model_path = 'data/output/model/val_accuracy_max.h5'
model = load_model(model_path)

#load data
img_path = 'images/images.jpg'
img = load_img(img_path)
img = img_to_array(img)
img = smart_resize(img, (72,72)) #resize to HxW
img = np.expand_dims(img, axis=0)

#prediction
y_pred = model.predict(img)
y_pred = np.argmax(y_pred, axis=1)

#see convert/output/label_decode.json
print(y_pred)

Smart resize (tf < 2.4.1)

from tensorflow.keras.preprocessing.image import img_to_array
from tensorflow.keras.preprocessing.image load_img
from tensorflow.python.ops import array_ops
from tensorflow.python.ops import image_ops
import numpy as np

def smart_resize(img, new_size, interpolation='bilinear'):
    """Resize images to a target size without aspect ratio distortion.

    Arguments:
      img (3D array): image data
      new_size (tuple): HxW

    Returns:
      [3D array]: image after resize
    """
    # Get infor of the image
    height, width, _ = img.shape
    target_height, target_width = new_size

    crop_height = (width * target_height) // target_width
    crop_width = (height * target_width) // target_height

    # Set back to input height / width if crop_height / crop_width is not smaller.
    crop_height = np.min([height, crop_height])
    crop_width = np.min([width, crop_width])

    crop_box_hstart = (height - crop_height) // 2
    crop_box_wstart = (width - crop_width) // 2

    # Infor to resize image
    crop_box_start = array_ops.stack([crop_box_hstart, crop_box_wstart, 0])
    crop_box_size = array_ops.stack([crop_height, crop_width, -1])

    img = array_ops.slice(img, crop_box_start, crop_box_size)
    img = image_ops.resize_images_v2(
        images=img,
        size=new_size,
        method=interpolation)
    return img.numpy()

Contributor

  1. BS Nguyen Truong Lau ([email protected])
  2. PhD Thai Trung Hieu ([email protected])

License

Distributed under the MIT License. See LICENSE for more information.

You might also like...
An end-to-end PyTorch framework for image and video classification
An end-to-end PyTorch framework for image and video classification

What's New: March 2021: Added RegNetZ models November 2020: Vision Transformers now available, with training recipes! 2020-11-20: Classy Vision v0.5 R

Scripts for training an AI to play the endless runner Subway Surfers using a supervised machine learning approach by imitation and a convolutional neural network (CNN) for image classification
Scripts for training an AI to play the endless runner Subway Surfers using a supervised machine learning approach by imitation and a convolutional neural network (CNN) for image classification

About subwAI subwAI - a project for training an AI to play the endless runner Subway Surfers using a supervised machine learning approach by imitation

PyTorch implementation of our method for adversarial attacks and defenses in hyperspectral image classification.
PyTorch implementation of our method for adversarial attacks and defenses in hyperspectral image classification.

Self-Attention Context Network for Hyperspectral Image Classification PyTorch implementation of our method for adversarial attacks and defenses in hyp

Code image classification of MNIST dataset using different architectures: simple linear NN, autoencoder, and highway network

Deep Learning for image classification pip install -r http://webia.lip6.fr/~baskiotisn/requirements-amal.txt Train an autoencoder python3 train_auto

A PyTorch Image-Classification With AlexNet And ResNet50.

PyTorch 图像分类 依赖库的下载与安装 在终端中执行 pip install -r -requirements.txt 完成项目依赖库的安装 使用方式 数据集的准备 STL10 数据集 下载:STL-10 Dataset 存储位置:将下载后的数据集中 train_X.bin,train_y.b

CNN Based Meta-Learning for Noisy Image Classification and Template Matching

CNN Based Meta-Learning for Noisy Image Classification and Template Matching Introduction This master thesis used a few-shot meta learning approach to

Code of Classification Saliency-Based Rule for Visible and Infrared Image Fusion

CSF Code of Classification Saliency-Based Rule for Visible and Infrared Image Fusion Tips: For testing: CUDA_VISIBLE_DEVICES=0 python main.py For trai

A python-image-classification web application project, written in Python and served through the Flask Microframework
A python-image-classification web application project, written in Python and served through the Flask Microframework

A python-image-classification web application project, written in Python and served through the Flask Microframework. This Project implements the VGG16 covolutional neural network, through Keras and Tensorflow wrappers, to make predictions on uploaded images.

All the essential resources and template code needed to understand and practice data structures and algorithms in python with few small projects to demonstrate their practical application.

Data Structures and Algorithms Python INDEX 1. Resources - Books Data Structures - Reema Thareja competitiveCoding Big-O Cheat Sheet DAA Syllabus Inte

Releases(v1.0.0)
Owner
Nguyễn Trường Lâu
AI Researcher at FPT Software
Nguyễn Trường Lâu
Simple-Image-Classification - Simple Image Classification Code (PyTorch)

Simple-Image-Classification Simple Image Classification Code (PyTorch) Yechan Kim This repository contains: Python3 / Pytorch code for multi-class ima

Yechan Kim 8 Oct 29, 2022
Implement face detection, and age and gender classification, and emotion classification.

YOLO Keras Face Detection Implement Face detection, and Age and Gender Classification, and Emotion Classification. (image from wider face dataset) Ove

Chloe 10 Nov 14, 2022
Hl classification bc - A Network-Based High-Level Data Classification Algorithm Using Betweenness Centrality

A Network-Based High-Level Data Classification Algorithm Using Betweenness Centr

Esteban Vilca 3 Dec 1, 2022
Vanilla and Prototypical Networks with Random Weights for image classification on Omniglot and mini-ImageNet. Made with Python3.

vanilla-rw-protonets-project Vanilla Prototypical Networks and PNs with Random Weights for image classification on Omniglot and mini-ImageNet. Made wi

Giovani Candido 8 Aug 31, 2022
Medical-Image-Triage-and-Classification-System-Based-on-COVID-19-CT-and-X-ray-Scan-Dataset

Medical-Image-Triage-and-Classification-System-Based-on-COVID-19-CT-and-X-ray-Sc

null 2 Dec 26, 2021
Code of U2Fusion: a unified unsupervised image fusion network for multiple image fusion tasks, including multi-modal, multi-exposure and multi-focus image fusion.

U2Fusion Code of U2Fusion: a unified unsupervised image fusion network for multiple image fusion tasks, including multi-modal (VIS-IR, medical), multi

Han Xu 129 Dec 11, 2022
This repository contains several image-to-image translation models, whcih were tested for RGB to NIR image generation. The models are Pix2Pix, Pix2PixHD, CycleGAN and PointWise.

RGB2NIR_Experimental This repository contains several image-to-image translation models, whcih were tested for RGB to NIR image generation. The models

null 5 Jan 4, 2023
Ready-to-use code and tutorial notebooks to boost your way into few-shot image classification.

Easy Few-Shot Learning Ready-to-use code and tutorial notebooks to boost your way into few-shot image classification. This repository is made for you

Sicara 399 Jan 8, 2023