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
Code for Towards Unifying Behavioral and Response Diversity for Open-ended Learning in Zero-sum Games

Unifying Behavioral and Response Diversity for Open-ended Learning in Zero-sum Games How to run our algorithm? Create the new environment using: conda

MARL @ SJTU 8 Dec 27, 2022
This repository is an implementation of our NeurIPS 2021 paper (Stylized Dialogue Generation with Multi-Pass Dual Learning) in PyTorch.

MPDL---TODO This repository is an implementation of our NeurIPS 2021 paper (Stylized Dialogue Generation with Multi-Pass Dual Learning) in PyTorch. Ci

CodebaseLi 3 Nov 27, 2022
Bayesian Optimization Library for Medical Image Segmentation.

bayesmedaug: Bayesian Optimization Library for Medical Image Segmentation. bayesmedaug optimizes your data augmentation hyperparameters for medical im

Şafak Bilici 7 Feb 10, 2022
CLUES: Few-Shot Learning Evaluation in Natural Language Understanding

CLUES: Few-Shot Learning Evaluation in Natural Language Understanding This repo contains the data and source code for baseline models in the NeurIPS 2

Microsoft 29 Dec 29, 2022
KGDet: Keypoint-Guided Fashion Detection (AAAI 2021)

KGDet: Keypoint-Guided Fashion Detection (AAAI 2021) This is an official implementation of the AAAI-2021 paper "KGDet: Keypoint-Guided Fashion Detecti

Qian Shenhan 35 Dec 29, 2022
Probabilistic Programming and Statistical Inference in PyTorch

PtStat Probabilistic Programming and Statistical Inference in PyTorch. Introduction This project is being developed during my time at Cogent Labs. The

Stefano Peluchetti 109 Nov 26, 2022
Read and write layered TIFF ImageSourceData and ImageResources tags

Read and write layered TIFF ImageSourceData and ImageResources tags Psdtags is a Python library to read and write the Adobe Photoshop(r) specific Imag

Christoph Gohlke 4 Feb 05, 2022
AIR^2 for Interaction Prediction

This is the repository for AIR^2 for Interaction Prediction. Explanation of the solution: Video: link License AIR is released under the Apache 2.0 lic

21 Sep 27, 2022
Code for ACL 21: Generating Query Focused Summaries from Query-Free Resources

marge This repository releases the code for Generating Query Focused Summaries from Query-Free Resources. Please cite the following paper [bib] if you

Yumo Xu 28 Nov 10, 2022
Exemplo de implementação do padrão circuit breaker em python

fast-circuit-breaker Circuit breakers existem para permitir que uma parte do seu sistema falhe sem destruir todo seu ecossistema de serviços. Michael

James G Silva 17 Nov 10, 2022
ZEBRA: Zero Evidence Biometric Recognition Assessment

ZEBRA: Zero Evidence Biometric Recognition Assessment license: LGPLv3 - please reference our paper version: 2020-06-11 author: Andreas Nautsch (EURECO

Voice Privacy Challenge 2 Dec 12, 2021
Deep Convolutional Generative Adversarial Networks

Unsupervised Representation Learning with Deep Convolutional Generative Adversarial Networks Alec Radford, Luke Metz, Soumith Chintala All images in t

Alec Radford 3.4k Dec 29, 2022
Simple helper library to convert a collection of numpy data to tfrecord, and build a tensorflow dataset from the tfrecord.

numpy2tfrecord Simple helper library to convert a collection of numpy data to tfrecord, and build a tensorflow dataset from the tfrecord. Installation

Ryo Yonetani 2 Jan 16, 2022
Beyond Image to Depth: Improving Depth Prediction using Echoes (CVPR 2021)

Beyond Image to Depth: Improving Depth Prediction using Echoes (CVPR 2021) Kranti Kumar Parida, Siddharth Srivastava, Gaurav Sharma. We address the pr

Kranti Kumar Parida 33 Jun 27, 2022
prior-based-losses-for-medical-image-segmentation

Repository for papers: Benchmark: Effect of Prior-based Losses on Segmentation Performance: A Benchmark Midl: A Surprisingly Effective Perimeter-based

Rosana EL JURDI 9 Sep 07, 2022
PyTorch code accompanying our paper on Maximum Entropy Generators for Energy-Based Models

Maximum Entropy Generators for Energy-Based Models All experiments have tensorboard visualizations for samples / density / train curves etc. To run th

Rithesh Kumar 135 Oct 27, 2022
The Self-Supervised Learner can be used to train a classifier with fewer labeled examples needed using self-supervised learning.

Published by SpaceML • About SpaceML • Quick Colab Example Self-Supervised Learner The Self-Supervised Learner can be used to train a classifier with

SpaceML 92 Nov 30, 2022
PyTorch implementation of DirectCLR from paper Understanding Dimensional Collapse in Contrastive Self-supervised Learning

DirectCLR DirectCLR is a simple contrastive learning model for visual representation learning. It does not require a trainable projector as SimCLR. It

Meta Research 49 Dec 21, 2022
Json2Xml tool will help you convert from json COCO format to VOC xml format in Object Detection Problem.

JSON 2 XML All codes assume running from root directory. Please update the sys path at the beginning of the codes before running. Over View Json2Xml t

Nguyễn Trường Lâu 6 Aug 22, 2022
Code release for the paper “Worldsheet Wrapping the World in a 3D Sheet for View Synthesis from a Single Image”, ICCV 2021.

Worldsheet: Wrapping the World in a 3D Sheet for View Synthesis from a Single Image This repository contains the code for the following paper: R. Hu,

Meta Research 37 Jan 04, 2023