{"id":20585393,"url":"https://github.com/eagerai/tfaddons","last_synced_at":"2026-03-11T01:01:35.793Z","repository":{"id":42974794,"uuid":"259372944","full_name":"EagerAI/tfaddons","owner":"EagerAI","description":"R interface to TensorFlow 2.x SIG-Addons ","archived":false,"fork":false,"pushed_at":"2023-09-19T14:22:40.000Z","size":1062,"stargazers_count":20,"open_issues_count":3,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-14T21:09:09.180Z","etag":null,"topics":["deep-learning","keras","neural-networks","r","tensorflow","tensorflow-addons","tfa"],"latest_commit_sha":null,"homepage":"https://eagerai.github.io/tfaddons/","language":"R","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/EagerAI.png","metadata":{"files":{"readme":"README.md","changelog":"NEWS.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-04-27T15:28:18.000Z","updated_at":"2022-08-03T12:56:51.000Z","dependencies_parsed_at":"2024-08-22T15:35:44.500Z","dependency_job_id":"926d23f4-7087-4760-9e24-7d69534e0883","html_url":"https://github.com/EagerAI/tfaddons","commit_stats":null,"previous_names":["henry090/tfaddons"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EagerAI%2Ftfaddons","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EagerAI%2Ftfaddons/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EagerAI%2Ftfaddons/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EagerAI%2Ftfaddons/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/EagerAI","download_url":"https://codeload.github.com/EagerAI/tfaddons/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248961237,"owners_count":21189993,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["deep-learning","keras","neural-networks","r","tensorflow","tensorflow-addons","tfa"],"created_at":"2024-11-16T07:07:54.769Z","updated_at":"2025-12-12T02:21:02.030Z","avatar_url":"https://github.com/EagerAI.png","language":"R","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n\n## R interface to useful extra functionality for TensorFlow 2.x by SIG-addons\n\nThe `tfaddons` package provides R wrappers to [TensorFlow Addons](https://www.tensorflow.org/addons).\n\n__TensorFlow Addons__ is a repository of contributions that conform to well-established API patterns, but implement new functionality not available in core TensorFlow. TensorFlow natively supports a large number of operators, layers, metrics, losses, and optimizers. However, in a fast moving field like ML, there are many interesting new developments that cannot be integrated into core TensorFlow (because their broad applicability is not yet clear, or it is mostly used by a smaller subset of the community).\n\n[![Actions Status](https://github.com/henry090/tfaddons/workflows/TFA_stable/badge.svg)](https://github.com/henry090/tfaddons)\n[![Actions Status](https://github.com/henry090/tfaddons/workflows/TFA/badge.svg)](https://github.com/henry090/tfaddons)\n[![CRAN](https://www.r-pkg.org/badges/version/tfaddons?color=darkgreen)](https://cran.r-project.org/package=tfaddons)\n[![Lifecycle: experimental](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://www.tidyverse.org/lifecycle/#experimental)\n[![Last month downloads](http://cranlogs.r-pkg.org/badges/last-month/tfaddons?color=green)](https://cran.r-project.org/package=tfaddons)\n[![Last commit](https://img.shields.io/github/last-commit/henry090/tfaddons.svg)](https://github.com/henry090/tfaddons/commits/master)\n\n![](https://img.shields.io/docker/cloud/build/turqut314/tfaddons?style=plastic)\n\n\u003cimg src=\"images/tfaddons.png\" width=200 align=right style=\"margin-left: 15px;\" alt=\"TF-addons\"/\u003e\n\nAddons provide the following features which are compatible with ```keras``` library.\n\n- activations\n- callbacks\n- image\n- layers\n- losses\n- metrics\n- optimizers\n- rnn\n- seq2seq\n- text\n\n## Installation\n\nRequirements:\n\n- TensorFlow 2.X\n\nThe dev version:\n\n```\ndevtools::install_github('henry090/tfaddons')\n```\n\nLater, you need to install the python module *tensorflow-addons*:\n\n```\ntfaddons::install_tfaddons()\n```\n\n## Usage: the basics\n\nHere's how to build a sequential model with ```keras``` using additional features from ```tfaddons``` package.\n\nImport and prepare MNIST dataset.\n\n```\nlibrary(keras)\nlibrary(tfaddons)\n\nmnist = dataset_mnist()\n\nx_train \u003c- mnist$train$x\ny_train \u003c- mnist$train$y\n\n# reshape the dataset\nx_train \u003c- array_reshape(x_train, c(nrow(x_train), 28, 28, 1))\n\n# Transform RGB values into [0,1] range\nx_train \u003c- x_train / 255\n\ny_train \u003c- to_categorical(y_train, 10)\n```\n\nUsing the Sequential API, define the model architecture.\n\n```\n# Build a sequential model\nmodel = keras_model_sequential() %\u003e% \n  layer_conv_2d(filters = 10, kernel_size = c(3,3),input_shape = c(28,28,1),\n                #apply activation gelu\n                activation = activation_gelu) %\u003e% \n  # apply group normalization layer\n  layer_group_normalization(groups = 5, axis = 3) %\u003e% \n  layer_flatten() %\u003e% \n  layer_dense(10, activation='softmax')\n\n# Compile\nmodel %\u003e% compile(\n  # apply rectified adam\n  optimizer = optimizer_radam(),\n  # apply sparse max loss\n  loss = loss_sparsemax(),\n  # choose cohen kappa metric\n  metrics = metric_cohen_kappa(10)\n)\n```\n\nTrain the Keras model.\n\n```\nmodel %\u003e% fit(\n  x_train, y_train,\n  batch_size = 128,\n  epochs = 1,\n  validation_split = 0.2\n)\n```\n\n```\nTrain on 48000 samples, validate on 12000 samples\n48000/48000 [==============================] - 24s 510us/sample - loss: 0.1193 - cohen_kappa: 0.8074 - \nval_loss: 0.0583 - val_cohen_kappa: 0.9104\n```\n\nLet's apply ```Weight Normalization```, a Simple Reparameterization technique to Accelerate Training of Deep Neural Networks:\n\n\u003e Note: We only change the model architecture and then train our model.\n\n```\n# Build a sequential model\nmodel = keras_model_sequential() %\u003e% \n  layer_weight_normalization(input_shape = c(28L,28L,1L),\n                             layer_conv_2d(filters = 10, kernel_size = c(3,3))) %\u003e% \n  layer_flatten() %\u003e% \n  layer_weight_normalization(layer_dense(units = 10, activation='softmax'))\n```\n\n```\nTrain on 48000 samples, validate on 12000 samples\n48000/48000 [==============================] - 12s 253us/sample - loss: 0.1276 - cohen_kappa: 0.7920 - \nval_loss: 0.0646 - val_cohen_kappa: 0.9044\n```\n\nWe can see that the training process has finished in *12 seconds*. But without this method, 1 epoch required *24 seconds*.\n\n## Callbacks\n\nOne can stop training after certain time. For this purpose, ```seconds``` parameter should be set in ```callback_time_stopping``` function:\n\n```\nmodel %\u003e% fit(\n  x_train, y_train,\n  batch_size = 128,\n  epochs = 4,\n  validation_split = 0.2,\n  verbose = 0,\n  callbacks = callback_time_stopping(seconds = 6, verbose = 1)\n)\n```\n\n```\nTimed stopping at epoch 1 after training for 0:00:06\n```\n\n## Losses\n\n```TripletLoss``` can be applied in the following form:\n\nFirst task is to create a Keras model.\n\n```\nmodel = keras_model_sequential() %\u003e% \n  layer_conv_2d(filters = 64, kernel_size = 2, padding='same', input_shape=c(28,28,1)) %\u003e% \n  layer_max_pooling_2d(pool_size=2) %\u003e% \n  layer_flatten() %\u003e% \n  layer_dense(256, activation= NULL) %\u003e% \n  layer_lambda(f = function(x) tf$math$l2_normalize(x, axis = 1L))\n\nmodel %\u003e% compile(\n  optimizer = optimizer_lazy_adam(),\n  # apply triplet semihard loss\n  loss = loss_triplet_semihard())\n```\n\nWith ```tfdatasets``` package we can *cast* our dataset and then ```fit```.\n\n```\nlibrary(tfdatasets)\n\ntrain = tensor_slices_dataset(list(tf$cast(x_train,'uint8'),tf$cast( y_train,'int64'))) %\u003e% \n  dataset_shuffle(1024) %\u003e% dataset_batch(32)\n  \n# fit\nmodel %\u003e% fit(\n  train,\n  epochs = 1\n)\n```\n\n```\nTrain for 1875 steps\n1875/1875 [==============================] - 74s 39ms/step - loss: 0.4227\n```\n\n\n\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feagerai%2Ftfaddons","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Feagerai%2Ftfaddons","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feagerai%2Ftfaddons/lists"}