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
Count the MACs / FLOPs of your PyTorch model.

THOP: PyTorch-OpCounter How to install pip install thop (now continously intergrated on Github actions) OR pip install --upgrade git+https://github.co

Ligeng Zhu 3.9k Dec 29, 2022
Pytorch Implementation for (STANet+ and STANet)

Pytorch Implementation for (STANet+ and STANet) V2-Weakly Supervised Visual-Auditory Saliency Detection with Multigranularity Perception (arxiv), pdf:

GuotaoWang 14 Nov 29, 2022
Federated Deep Reinforcement Learning for the Distributed Control of NextG Wireless Networks.

FDRL-PC-Dyspan Federated Deep Reinforcement Learning for the Distributed Control of NextG Wireless Networks. This repository contains the entire code

Peyman Tehrani 17 Nov 18, 2022
Codes for NAACL 2021 Paper "Unsupervised Multi-hop Question Answering by Question Generation"

Unsupervised-Multi-hop-QA This repository contains code and models for the paper: Unsupervised Multi-hop Question Answering by Question Generation (NA

Liangming Pan 70 Nov 27, 2022
DilatedNet in Keras for image segmentation

Keras implementation of DilatedNet for semantic segmentation A native Keras implementation of semantic segmentation according to Multi-Scale Context A

303 Mar 15, 2022
From Fidelity to Perceptual Quality: A Semi-Supervised Approach for Low-Light Image Enhancement (CVPR'2020)

Under-exposure introduces a series of visual degradation, i.e. decreased visibility, intensive noise, and biased color, etc. To address these problems, we propose a novel semi-supervised learning app

Yang Wenhan 117 Jan 03, 2023
TensorFlow Tutorial and Examples for Beginners (support TF v1 & v2)

TensorFlow Examples This tutorial was designed for easily diving into TensorFlow, through examples. For readability, it includes both notebooks and so

Aymeric Damien 42.5k Jan 08, 2023
ParaGen is a PyTorch deep learning framework for parallel sequence generation

ParaGen is a PyTorch deep learning framework for parallel sequence generation. Apart from sequence generation, ParaGen also enhances various NLP tasks, including sequence-level classification, extrac

Bytedance Inc. 169 Dec 22, 2022
🚩🚩🚩

My CTF Challenges 2021 AIS3 Pre-exam / MyFirstCTF Name Category Keywords Difficulty ⒸⓄⓋⒾⒹ-①⑨ (MyFirstCTF Only) Reverse Baby ★ Piano Reverse C#, .NET ★

6 Oct 28, 2021
The best solution of the Weather Prediction track in the Yandex Shifts challenge

yandex-shifts-weather The repository contains information about my solution for the Weather Prediction track in the Yandex Shifts challenge https://re

Ivan Yu. Bondarenko 15 Dec 18, 2022
code for our paper "Source Data-absent Unsupervised Domain Adaptation through Hypothesis Transfer and Labeling Transfer"

SHOT++ Code for our TPAMI submission "Source Data-absent Unsupervised Domain Adaptation through Hypothesis Transfer and Labeling Transfer" that is ext

75 Dec 16, 2022
zeus is a Python implementation of the Ensemble Slice Sampling method.

zeus is a Python implementation of the Ensemble Slice Sampling method. Fast & Robust Bayesian Inference, Efficient Markov Chain Monte Carlo (MCMC), Bl

Minas Karamanis 197 Dec 04, 2022
This is the reference implementation for "Coresets via Bilevel Optimization for Continual Learning and Streaming"

Coresets via Bilevel Optimization This is the reference implementation for "Coresets via Bilevel Optimization for Continual Learning and Streaming" ht

Zalán Borsos 51 Dec 30, 2022
A working implementation of the Categorical DQN (Distributional RL).

Categorical DQN. Implementation of the Categorical DQN as described in A distributional Perspective on Reinforcement Learning. Thanks to @tudor-berari

Florin Gogianu 98 Sep 20, 2022
ZSL-KG is a general-purpose zero-shot learning framework with a novel transformer graph convolutional network (TrGCN) to learn class representation from common sense knowledge graphs.

ZSL-KG is a general-purpose zero-shot learning framework with a novel transformer graph convolutional network (TrGCN) to learn class representa

Bats Research 94 Nov 21, 2022
Single-Shot Motion Completion with Transformer

Single-Shot Motion Completion with Transformer 👉 [Preprint] 👈 Abstract Motion completion is a challenging and long-discussed problem, which is of gr

FuxiCV 78 Dec 29, 2022
Array Camera Ptychography

Array Camera Ptychography This repository provides the code for the following papers: Schulz, Timothy J., David J. Brady, and Chengyu Wang. "Photon-li

Brady lab in Optical Sciences 1 Nov 15, 2021
Retinal Vessel Segmentation with Pixel-wise Adaptive Filters (ISBI 2022)

Official code of Retinal Vessel Segmentation with Pixel-wise Adaptive Filters and Consistency Training (ISBI 2022)

anonymous 14 Oct 27, 2022
Official PyTorch implementation of DD3D: Is Pseudo-Lidar needed for Monocular 3D Object detection? (ICCV 2021), Dennis Park*, Rares Ambrus*, Vitor Guizilini, Jie Li, and Adrien Gaidon.

DD3D: "Is Pseudo-Lidar needed for Monocular 3D Object detection?" Install // Datasets // Experiments // Models // License // Reference Full video Offi

Toyota Research Institute - Machine Learning 364 Dec 27, 2022
Stratified Transformer for 3D Point Cloud Segmentation (CVPR 2022)

Stratified Transformer for 3D Point Cloud Segmentation Xin Lai*, Jianhui Liu*, Li Jiang, Liwei Wang, Hengshuang Zhao, Shu Liu, Xiaojuan Qi, Jiaya Jia

DV Lab 195 Jan 01, 2023