<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Subham Kumar Das on Medium]]></title>
        <description><![CDATA[Stories by Subham Kumar Das on Medium]]></description>
        <link>https://medium.com/@lost_particles?source=rss-36fad853d756------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*rsSQv-DzMONWYDRhIRryvQ.png</url>
            <title>Stories by Subham Kumar Das on Medium</title>
            <link>https://medium.com/@lost_particles?source=rss-36fad853d756------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 29 Nov 2026 21:24:41 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@lost_particles/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Federated Recon: GAN-Based Reconstruction Attack In A Federated Learning Setup]]></title>
            <link>https://medium.com/@lost_particles/federated-recon-gan-based-reconstruction-attack-in-a-federated-learning-setup-4545672162e3?source=rss-36fad853d756------2</link>
            <guid isPermaLink="false">https://medium.com/p/4545672162e3</guid>
            <category><![CDATA[federated-learning]]></category>
            <category><![CDATA[model-inversion-attack]]></category>
            <category><![CDATA[gans]]></category>
            <category><![CDATA[ai-privacy-and-security]]></category>
            <category><![CDATA[data-leak]]></category>
            <dc:creator><![CDATA[Subham Kumar Das]]></dc:creator>
            <pubDate>Tue, 15 Jul 2025 05:52:48 GMT</pubDate>
            <atom:updated>2025-07-15T05:52:48.714Z</atom:updated>
            <content:encoded><![CDATA[<p>A deep dive into how GANs can reconstruct private data in a federated learning setup. This article aims to demonstrate the hidden vulnerabilities behind gradient sharing and explains why privacy in a decentralized training framework may not be as secure as it appears. My <a href="https://github.com/lost-particles/federatedRecon"><em>implementation of GAN based reconstruction attack</em></a> is based on/inspired by research paper <a href="https://arxiv.org/abs/1906.08935"><em>Deep Leakage from Gradients</em></a> and <a href="https://doi.org/10.1145/3133956.3134012"><em>Deep Models Under the GAN: Information Leakage from Collaborative Deep Learning</em></a><em> .</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*B5P9EEtvUQUN4HMyRc0Gpg.png" /></figure><h3>Understanding Federated Learning</h3><p>Let’s say you want to train a model to predict cancerous tumors by processing X-Ray, CT, or MRI scans of patients. To effectively detect these abnormalities, the model must be trained on sensitive, private data(protected under HIPAA laws) from multiple hospitals and diverse demographic groups, ensuring it can generalize well across different populations.</p><p>However, this data cannot be shared outside the hospital that owns it without explicit permission, due to strict privacy regulations. As a result, training a centralized model becomes a complex and cumbersome logistical challenge. This is where Federated Learning (FL) offers a powerful solution. FL is a collaborative approach in which a global model is trained across multiple local models, each operating privately within its own institution.</p><figure><img alt="Federated Learning Setup showcasing, how 3 hospitals participate and exchange model updates(Generated by chatGpt)" src="https://cdn-images-1.medium.com/max/1024/1*NMrOPuGglzlAwH5CqQ7bfA.png" /><figcaption><strong>Img 1</strong>: Federated Learning Setup with 3 participating Hospitals (Image generated by chatGPT)</figcaption></figure><p>In this scenario, let’s say we have 3 hospitals <strong>H1</strong>, <strong>H2</strong> and <strong>H3</strong>. Each of these hospitals would have a local model setup, which is trained on their own respective private patient data that they hold. With every round of training, all the 3 local models would send their model weights as updates to a global model(which is accessible to all the participating entity). Then the global model aggregates these updates to generalize over wider spread of data. And after the aggregation, all the 3 hospitals would get the aggregated Model weights. Upon receiving these new aggregated weights, a new round starts where all the local models restart the learning process on their respective private data from these new weights. This cycle continues for multiple rounds which allows the global model to recognise pattern from a wider range of data, even though it has not seen the data directly.</p><p>As demonstrated, multiple entities collaborated to train a model capable of detecting cancerous tumors without ever sharing private data with one another. This approach captures the essence of Federated Learning, which enables a wide range of applications while preserving data privacy.</p><h3>What is a Generative Adversarial Network(GAN) ?</h3><p>As the name suggests, A GAN is a machine learning model that can generate new data(be it images, text, etc.) which closely resembles, the training dataset i.e the new generated data would be in the same data distribution as the training data. For instance, if a GAN is trained on a dataset of Puppy images, it can generate new puppy images that it has never seen before.</p><p>GAN comprises of 2 neural networks, namely Generator(denoted as <strong>G</strong>) and a Discriminator(denoted as <strong>D</strong>).</p><p>The Generator is responsible for generating data and the Discriminator is responsible for detecting fake from real data. During the training process the Generator network optimizes its loss function to fool the Discriminator network, whereas the Discriminator network optimizes its loss function to distinguish real data from generated data(i.e fake data). They go back &amp; forth training each other in a feedback loop.</p><h3>Attack Vector</h3><p>Let’s say, we have a federated setup with multiple parties contributing to the model training. Only one compromised party(Adversary) with nefarious intentions can reconstruct the data from other parties, effectively stealing/leaking sensitive information. During training phase, a ML model learns by back propagating the loss to update the model weights. So Intuitively, it is reasonable to assume that inherently there is some information stored in the model weights corresponding to the patterns of the training data.</p><p>Therefore, all we have to do is to reverse engineer the weights to recreate that pattern. That’s where the GAN comes in. The Adversary can use a GAN to learn the distribution of the training data by using the aggregated weights received from the global model during each round of the federated training.</p><p>Let’s understand how all of this come together. Going back to the previous example of 3 hospitals contributing to a model training, let’s say Hospital H1 is a adversary party trying to leak data from H2 and H3. In addition to the local model used for FL, H1 can initialize a separate Generator(G) neural network which tries to learn to predict the underlying data.</p><p>But wait!! Don’t we need a Discriminator to train our adversary generator G ? Yes we do. So in this scenario, we will use the currently training model(that updates with new model weight from the global model every round) as a Discriminator. So as we proceed to later rounds in the FL training, the Discriminator which is trained by aggregated model weights gets better and better. As a result, it gives better feedback to the H1’s generator network which learns faster to generate reliable and real looking data.</p><h3>Implementation Details</h3><p>My implementation of this attack can be found here : <a href="https://github.com/lost-particles/federatedRecon"><strong><em>FederatedRecon</em></strong></a></p><p>First of all, we have to simulate a federated learning setup with multiple parties. For that I am locally simulating it by using <a href="https://flower.ai/"><strong><em>Flower framework</em></strong></a><strong><em>.</em></strong> The details about installing Flower and setting up a basic FL environment is provided on their official documentation. Do check that out.</p><p>To keep things simple for this demonstration, we’ll use two parties in our Federated Learning (FL) setup: Party 1 and Party 2. We’ll begin by training a global model to classify digits from the <strong>MNIST digit dataset</strong>. Later, we’ll explore the attack scenario using a face dataset.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*FtakZbpUJSc1WKqTq_0MVw.png" /><figcaption><strong>Img 2</strong>: FL Setup for MNIST Dataset Classifier (Img generated by Claude AI)</figcaption></figure><p><strong>Note*:</strong></p><ol><li><strong>We partition the MNIST digit dataset in such a way that, Party 1 has exclusive access to images of digits 0, 1, 2, 3 &amp; 4 and Party 2 has exclusive access to images of digits 5, 6, 7, 8 &amp; 9 (refer Img 2). So these images act as private data i.e Party 1 would never see the images for digits 5,6,7,8 &amp; 9 and vice-versa.</strong></li><li><strong>When the global model is initialized for digit classification , it is assigned with 10 classes corresponding to 10 digits. So, that means both the parties are aware that there are 10 different labels, even though each party might not have seen images for all the labels.</strong></li><li><strong>Here, Party 1 will act as a Adversary and try to reconstruct images that it has never seen corresponding to labels 5, 6, 7, 8 &amp; 9.</strong></li></ol><h4>Architecture Details</h4><blockquote>CNN(used for both the global &amp; local model)</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*3wQgL188-5xFk7pDu8J6fg.png" /><figcaption><strong>Img 3</strong>: CNN Architecture (Img generated by Claude AI)</figcaption></figure><pre>● CNN architecture for local &amp; global model(for digit recognition) :<br>○ | **Layer Type** | **Details** |<br>○ | --------------------- | ------------------------------------------- |<br>○ | Input | Grayscale Image (1 channel, 28×28) |<br>○ | Conv2D + ReLU | 6 filters, 5×5 kernel, stride 1 |<br>○ | MaxPooling | 2×2 kernel, stride 2 |<br>○ | Conv2D + ReLU | 16 filters, 5×5 kernel, stride 1 |<br>○ | MaxPooling | 2×2 kernel, stride 2 |<br>○ | Flatten | Convert to 1D feature vector |<br>○ | Fully Connected (FC1) | Linear layer → 120 neurons + ReLU |<br>○ | Fully Connected (FC2) | Linear layer → 84 neurons + ReLU |<br>○ | Output Layer (FC3) | Linear layer → 10 output logits (0–9 class) |</pre><blockquote>Generator Model (used by Adversary)</blockquote><pre>#Generator to be used by the Adversary<br>class Generator(nn.Module):<br>    def __init__(self, noise_dim=100, num_classes=10, out_channels=1, feature_maps=128):<br>        super(Generator, self).__init__()<br>        self.label_emb = nn.Embedding(num_classes, num_classes)<br><br>        input_dim = noise_dim + num_classes<br>        self.project = nn.Sequential(<br>            nn.Linear(input_dim, feature_maps * 4 * 7 * 7),<br>            nn.BatchNorm1d(feature_maps * 4 * 7 * 7),<br>            nn.ReLU(True)<br>        )<br><br>        self.net = nn.Sequential(<br>            nn.ConvTranspose2d(feature_maps * 4, feature_maps * 2, kernel_size=4, stride=2, padding=1),  # 7x7 → 14x14<br>            nn.BatchNorm2d(feature_maps * 2),<br>            nn.ReLU(True),<br><br>            nn.ConvTranspose2d(feature_maps * 2, feature_maps, kernel_size=4, stride=2, padding=1),  # 14x14 → 28x28<br>            nn.BatchNorm2d(feature_maps),<br>            nn.ReLU(True),<br><br>            nn.Conv2d(feature_maps, out_channels, kernel_size=3, stride=1, padding=1),  # 28x28<br>            nn.Tanh()<br>        )<br><br>    def forward(self, z, labels):<br>        # Embed labels and concatenate<br>        label_embed = self.label_emb(labels)<br>        input_vec = torch.cat([z.squeeze(), label_embed], dim=1)<br>        out = self.project(input_vec)<br>        out = out.view(out.size(0), -1, 7, 7)<br>        return self.net(out)</pre><h3>Optimizations &amp; Considerations</h3><ol><li>Generator is trained on <strong>conditioned label: </strong>The generator in this setup is not trained to produce arbitrary digits, but rather is <strong>conditioned</strong> on a specific label — in this case, digit <strong>“9”</strong>. That means the generator is explicitly trying to synthesize images that resemble handwritten “9”s. This is crucial because the generator <strong>belongs to a malicious party (e.g., Party 1)</strong> that <strong>doesn’t have access to real samples of class 9</strong>, which are held exclusively by Party 2. By conditioning on a label, the generator learns to produce targeted outputs, which helps in evaluating and demonstrating the <strong>leakage potential</strong> more clearly.</li><li>Losses Used :<br>• <strong>Confidence Loss(Target Logit Maximization)</strong> : This pushes the generated images to be <strong>classified confidently</strong> as the target class by the frozen global model (used as a surrogate discriminator).<br>• <strong>Diversity Loss</strong> : This loss <strong>encourages the features</strong> produced by the model to be <strong>dissimilar</strong> between the two halves of a batch.</li><li><strong>Delayed Generator Training</strong>: Instead of training the generator from the very beginning (when the global model is still untrained or weak), the training is <strong>delayed until the global model has learned meaningful digit features</strong>.<br>• If training begins too early, the generator could pick up on <strong>random noise patterns</strong> or unstable gradients, resulting in poor quality or meaningless outputs.<br>• Delaying allows the generator to learn from a <strong>richer and more semantically useful feature space</strong>, enhancing the <strong>quality of the reconstructed digits</strong>.</li><li><strong>Use of features extracted from inner layers of the discriminator</strong>: Rather than using only the model’s final classification output, this setup leverages <strong>features extracted from intermediate (inner) layers</strong> of the global model.<br>• These features often encode <strong>rich structural and spatial information</strong>, such as strokes, shapes, and edges.<br>• Using them improves <strong>fidelity and realism</strong> of the generated images, as they help the generator understand <strong>how “9” is internally represented</strong> by the model.</li></ol><h3>Results</h3><blockquote>Note that the image on the right has been generated by the generator(Adversary), without ever having seen the images for handwritten digit ‘9’.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/122/1*2tjLtyZ9encWKDbjZhzHpw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/122/1*QGPp4JjEMQ2qwb6pYGklgg.png" /><figcaption><strong>Img 4(Left)</strong>: Initial 4 X 4 grid generated by Generator(Pure Noise); <strong>Img 5(Right)</strong>: Reconstruction after 5 rounds of Generator training(from round 5 to round 10);</figcaption></figure><blockquote>This is the key highlight: the generator has <strong>never directly accessed any samples of the digit ‘9’</strong>, yet is able to <strong>recreate realistic images</strong> of it.<br> This illustrates the <strong>power and danger</strong> of this type of attack — it exploits <strong>information encoded in shared model updates</strong>, not data itself. The global model has indirectly encoded characteristics of class “9” (learned from Party 2), and the generator is mining this knowledge to perform a <strong>model inversion-style reconstruction attack</strong>.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/488/1*cnfUsG47cheUfAIvageAbQ.gif" /><figcaption><strong>Gif 6</strong>: Timelapse of the digit “9” emerging from noise over 5 rounds of training the Generator</figcaption></figure><p>The above Gif shows how the digit “9” emerges slowly as we go over 5 rounds of training the Generator network.</p><h4>Exploratory Runs for CelebA Dataset</h4><p>The objective in this experiment is to reconstruct the face of a specific celebrity, even though the participating party has never seen the actual image. Achieving this requires a substantial amount of data and computational power. Nonetheless, I conducted several exploratory training rounds to observe how an RGB image gradually takes shape over time.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/525/1*VxXr1LqYoWDHDu1NTE2tMQ.png" /><figcaption><strong>Img 7</strong>: A faint face structure generated by the Generator</figcaption></figure><p>As shown, even after a limited number of training iterations, the generator starts to capture general facial features that are commonly present across samples in the dataset. The broader goal is to collect a sufficient number of images of a targeted celebrity (class-specific generation) and refine the training process to the point where the generator can produce a realistic reconstruction of that individual’s face. Below is the time lapse showing the face structure emerging over 5 rounds of generator training.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/532/1*vNQ18odNxgk7GRoXouvA_A.gif" /><figcaption><strong>Gif 8</strong>: A faint face structure evolving over 5 rounds of Generator training</figcaption></figure><h3><strong>Attack Mitigation Strategies (INEFFECTIVE)</strong></h3><p>Below are few mitigation strategies are their tradeoffs:</p><ol><li><strong>Differential Privacy:</strong> Adds noise to the model updates to obscure individual data contributions. While this makes it harder for an adversary to reconstruct private data, it is not foolproof. A strong adversary can still extract useful patterns, especially if the privacy budget is weak. Additionally, applying too much noise can significantly reduce the accuracy of the global model.</li><li><strong>Secure Aggregation:</strong> Prevents the server from seeing individual client updates by only allowing access to aggregated model updates. This is effective when the threat comes from the server itself. However, in scenarios like ours where the adversary is one of the clients, secure aggregation offers no protection because the malicious client still receives the global model updates directly.</li><li><strong>Homomorphic Encryption:</strong> Enables computations to be done on encrypted data without revealing the raw values. While this protects data during processing, it doesn’t stop a malicious client from receiving the global model after each round. The adversary can still use the decrypted model to carry out reconstruction attacks, defeating the purpose of HE in this context.</li></ol><blockquote>While existing defenses raise the barrier for data leakage, they do not eliminate it. To the untrained eye,<strong> federated learning may appear inherently secure</strong> — after all, the <strong>raw data never leaves each party</strong>. But security is not about where the data sits; it’s about what can be inferred from what is shared. Federated learning promises privacy by design, but in practice, privacy must be earned through rigorous threat modeling and robust safeguards.</blockquote><h3>References</h3><ol><li>Briland Hitaj, Giuseppe Ateniese, and Fernando Perez-Cruz. 2017. Deep Models Under the GAN: Information Leakage from Collaborative Deep Learning. In Proceedings of the 2017 ACM SIGSAC Conference on Computer and Communications Security (CCS ‘17). Association for Computing Machinery, New York, NY, USA, 603–618. <a href="https://doi.org/10.1145/3133956.3134012">https://doi.org/10.1145/3133956.3134012</a></li><li>Ligeng Zhu, Zhijian Liu, and Song Han. 2019. <em>Deep Leakage from Gradients</em>. arXiv:1906.08935 [cs.LG]. <a href="https://doi.org/10.48550/arXiv.1906.08935">https://doi.org/10.48550/arXiv.1906.08935</a></li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4545672162e3" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>