Coder Social home page Coder Social logo

leihao1999 / keras_cosine_based_loss Goto Github PK

View Code? Open in Web Editor NEW

This project forked from samisoto/keras_cosine_based_loss

0.0 0.0 0.0 201 KB

Keras Custom Layers of AdaCos and ArcFace contains experiments in caltech birds 2011(CUB-200-2011).

License: Creative Commons Zero v1.0 Universal

Python 100.00%

keras_cosine_based_loss's Introduction

Keras Custom Layers of AdaCos and ArcFace

Keras Custom Layers of AdaCos and ArcFace, and experiments in caltech birds 2011(CUB-200-2011).

Original Paper

Building Model sample by the Functional API

num_classes = 200 # CUB-200-2011
img_size = 224    # EfficientNetB0

from CustomLayer import AdaCos
feature_extractor_layer = hub.KerasLayer("https://tfhub.dev/tensorflow/efficientnet/b0/feature-vector/1", name='efficientnetB0')
input_image = tf.keras.Input(shape=(img_size, img_size, 3), dtype=tf.float32, name='input_image')
efficientnet_output = feature_extractor_layer(input_image)

cos_layer = CosineLayer(num_classes=num_classes)
cos_layer_output = cos_layer(efficientnet_output)

logits = AdaCos_logits()([cos_layer_output, y_true])

model = tf.keras.models.Model(inputs=(input_image, y_true), outputs=tf.keras.layers.Softmax()(logits)

Requirements

  • tensorflow > 2.2
  • tensorflow_probability

Experiments in caltech birds 2011(CUB-200-2011)

  • Using data

    caltech_birds tfds (https://www.tensorflow.org/datasets/catalog/caltech_birds2011).

  • Preprocess

    crop to bounding box, general augmentation(flip, brightness, rotate, etc.), resize to [224,224,3] (EfficientnetB0) and return ((image, label), label) for using label to train

    >>>train_batches
    <MapDataset shapes: (((None, None, None, 3), (None, 1)), (None,)), types: ((tf.float32, tf.int64), tf.int64)>
    
  • Model

    EfficientNetB0 with AdaCos, fixedAdaCos, ArcFace, l2-softmax and softmax

  • Result

    • Accuracy of test data is almost same(0.82) except for softmax(0.8).

    • AdaCos value of s gradually decreases as with the paper.

    • Average cosθ of correct label increases to near 1(θ = 0) in AdaCos and fixedAdaCos.

keras_cosine_based_loss's People

Contributors

samisoto avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.