{"id":13562439,"url":"https://github.com/mccorby/PhotoLabeller","last_synced_at":"2025-04-03T18:33:41.578Z","repository":{"id":41262864,"uuid":"124423467","full_name":"mccorby/PhotoLabeller","owner":"mccorby","description":"Federated Learning: Client application doing classification of images and local training. Works better with the Parameter Server at https://github.com/mccorby/PhotoLabellerServer","archived":false,"fork":false,"pushed_at":"2019-03-18T10:34:39.000Z","size":8421,"stargazers_count":144,"open_issues_count":2,"forks_count":24,"subscribers_count":12,"default_branch":"master","last_synced_at":"2024-12-06T22:37:20.068Z","etag":null,"topics":["android","deeplearning4j","dl4j","edge-computing","federated-learning","kotlin","machine-learning"],"latest_commit_sha":null,"homepage":"","language":"Kotlin","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mccorby.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-03-08T17:11:13.000Z","updated_at":"2024-11-26T03:26:36.000Z","dependencies_parsed_at":"2022-08-25T20:40:25.257Z","dependency_job_id":null,"html_url":"https://github.com/mccorby/PhotoLabeller","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mccorby%2FPhotoLabeller","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mccorby%2FPhotoLabeller/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mccorby%2FPhotoLabeller/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mccorby%2FPhotoLabeller/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mccorby","download_url":"https://codeload.github.com/mccorby/PhotoLabeller/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247057074,"owners_count":20876508,"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":["android","deeplearning4j","dl4j","edge-computing","federated-learning","kotlin","machine-learning"],"created_at":"2024-08-01T13:01:08.615Z","updated_at":"2025-04-03T18:33:36.562Z","avatar_url":"https://github.com/mccorby.png","language":"Kotlin","funding_links":[],"categories":["Kotlin","Projects","federated learning framework"],"sub_categories":["2015","table"],"readme":"**Check [this blog entry](https://proandroiddev.com/federated-learning-e79e054c33ef) for more information**\n\n# Federated Learning\nThis project is an implementation of a [Federated Learning](https://research.googleblog.com/2017/04/federated-learning-collaborative.html) system consisting on a [Parameter Server](https://github.com/mccorby/PhotoLabellerServer) and an [Android application](https://github.com/mccorby/PhotoLabeller) that can be used as a client\n\nBoth components are implemented in Kotlin using DL4J as the Machine Learning framework\n\n\nEnjoy!\n\n## The problem\nTraining a machine learning model requires data. The more we have, the better (well... not always, but let's allow some simplifications). However, data is not cheap and more importantly, it can contain sensitive and personal information.\n\nRecent developments in privacy in the form of new laws as [GDPR](https://www.eugdpr.org/) and the increase of awareness of users and citizens in the value of their data is generating a need for techniques to enforce more privacy\n\nThough techniques as [anonymisation](https://ico.org.uk/for-organisations/guide-to-data-protection/anonymisation/) can greatly help with the privacy issue the fact that all the data is being sent to a central location to train the machine learning models is always a motive to be worried about\n\n\n## Federated Learning as a solution to privacy\nFederated Learning turns the update of Machine Learning models upside-down by allowing the devices on the edge to participate in the training.\n\nInstead of sending the data in the client to a centralised location, Federated Learning sends the model to the devices participating in the federation. The model is then re-trained (using [Transfer Learning](http://ruder.io/transfer-learning/)) with the local data\n\nAnd the data, your data, never leaves the device, let that be your phone, your laptop or your IoT gadget\n\n## High-level Architecture\n\n![image alt text](art/high_level_arch.png)\n\nVery briefly the process of training a model goes as follows:\n* The server opens a new round of training\n* The clients that are going to participate in the training round download the latest version of the model from the server\n* Using their local data, each client updates the model\n* Those updates are sent to the server\n* The server gathers all updates and applies Federated Averaging to improve the shared model\n* The shared model is now ready for all clients to use\n\n## Use Case. Classifying and training images\n\nTo demonstrate how Federated Learning works, I have implemented a system based on Cifar-10, a well-known image classification dataset\n\n### Android client\n\n| ![image alt text](art/App_Predicting.png) | ![image alt text](art/App_Training.png) |\n\n#### Client Architecture\n\nThe architecture allows to remove the UI bit in Android and apply the rest with little effort to another type of client that supports Kotlin\n\n### Parameter Server\n#### Server Architecture\n#### Federated Averaging\nThe averaging is done by the server once it has received a minimum number of updates. It applies Federated Averaging as defined in [1]()\n\nSee [FederatedAveragingStrategy.kt](https://github.com/mccorby/PhotoLabellerServer/blob/master/server/src/main/kotlin/com/mccorby/photolabeller/server/core/FederatedAveragingStrategy.kt)\n\n```java\n    override fun processUpdates(): ByteArrayOutputStream {\n        val totalSamples = repository.getTotalSamples()\n        val model = ModelSerializer.restoreMultiLayerNetwork(repository.retrieveModel())\n        val shape = model.getLayer(layerIndex).params().shape()\n\n        val sumUpdates = repository.listClientUpdates().fold(\n                Nd4j.zeros(shape[0], shape[1]),\n                { sumUpdates, next -\u003e processSingleUpdate(next, totalSamples, sumUpdates) }\n        )\n\n        model.getLayer(layerIndex).setParams(sumUpdates)\n        val outputStream = ByteArrayOutputStream()\n        ModelSerializer.writeModel(model, outputStream, true)\n        repository.storeModel(outputStream.toByteArray())\n        return outputStream\n    }\n ```\n\n## References\n* [Federated Learning](https://research.googleblog.com/2017/04/federated-learning-collaborative.html)\n* [OpenMined](https://www.openmined.org/)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmccorby%2FPhotoLabeller","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmccorby%2FPhotoLabeller","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmccorby%2FPhotoLabeller/lists"}