This repository explores Semantic Auto-Encoders for robust communication over noisy channels with LDPC coding and semantic interference cancellation (SemantIC).
It provides implementations of:
- A semantic encoder–decoder (RED-CNN style) trained on CIFAR-10
- A GoogLeNet-inspired classifier to maintain task accuracy after compression
- A SemantIC pipeline that enhances LDPC decoding on AWGN channels using semantic extrinsic information
Author: Md. Iqbal Haider Khan (@ihkokil) LinkedIn: Md. Iqbal Haider Khan (@ihkokil) License: MIT
- Overview
- Results
- Quickstart
- Training
- SemantIC Testing
- Project Structure
- Configuration & Tips
- Dependencies
- Acknowledgements
- Citation
- License
This project demonstrates how semantic auto-encoders can improve information quality in 6G-like networks by:
- Compressing images into compact latent representations optimized for a downstream classifier (GoogLeNet)
- Transmitting over a noisy AWGN channel with LDPC coding
- Using semantic interference cancellation (SemantIC) to inject semantic-level extrinsic information into the LDPC decoder
- Improving bit error rate (BER) and reconstruction quality compared to conventional pipelines
googlenet_train.py— Train CIFAR-10 classifierENC_DEC_train.py— Train semantic encoder/decoder with perceptual + task lossSemantIC.py— Perform LDPC coding/decoding over AWGN with semantic extrinsic information
Below: Original vs Distorted vs SemantIC Reconstruction
| Original | Distorted | SemantIC (Reconstructed) |
|---|---|---|
![]() |
![]() |
![]() |
- Python 3.13
- PyTorch 1.13.0
# (Recommended) create a new environment
# conda create -n semantic-6g python=3.10 -y && conda activate semantic-6g
pip install -r requirements.txtrequirements.txt example:
torch==1.13.0
torchvision==0.14.0
numpy
scipy
numba
pillow
imageio
pandas- CIFAR-10 is automatically downloaded to
./dataon first run.
-
Scripts use CUDA if available.
-
You can set a specific GPU via:
export CUDA_VISIBLE_DEVICES=0
python googlenet_train.py- Saves weights as
google_net.pklafter each epoch.
python ENC_DEC_train.py --alpha 0.8 --pretrain_epoch 0--alpha: weight for task loss (default 0.8)--pretrain_epoch: warmup with MSE-only loss (default 0)compression_rate: defined inside script (default 0.3)
Outputs:
semantic_coder.pkl- Classifier checkpoints (e.g.,
google_net_final-lambda-XX.pkl) - Sample reconstructions →
images/ - Training logs (accuracy, PSNR) →
./CIFAR/MLP_sem_CIFAR/*.csv
Run:
python SemantIC.pyPipeline:
- Load CIFAR-10 & semantic coder (
semantic_coder.pkl) - Quantize latent → binary stream (8-bit)
- LDPC encode (n=900, d_v=2, d_c=3)
- Transmit via AWGN at SNR ∈ {-5, …, 9} dB
- Iterative LDPC decoding + semantic extrinsic LLR injection
- Save outputs & metrics
Outputs:
- Per-SNR images:
images/snr{snr}/origin-semantic-{epoch}-{iter}.png - Logs:
images/snr{snr}.csv(BER + Energy Distance metrics)
Customizable Parameters:
- Epoch length, batch size → inside
SemantIC.py - SNR range →
range(-5, 10) - LDPC settings →
n_code, d_v, d_c
.
├── ENC_DEC_train.py # Train semantic encoder/decoder
├── googlenet_train.py # Train CIFAR-10 classifier (GoogLeNet-like)
├── SemantIC.py # LDPC + AWGN + semantic interference cancellation
├── LDPC/
│ ├── code.py
│ ├── decoder.py
│ ├── encoder.py
│ ├── ldpc_audio.py
│ ├── ldpc_images.py
│ ├── utils.py
│ ├── utils_audio.py
│ └── utils_img.py
├── images/ # Outputs (generated automatically)
│ └── result/ # Example figures for README
│ ├── original.png
│ ├── distorted.png
│ └── semantic.png
├── data/ # CIFAR-10 (auto-downloaded)
├── requirements.txt
└── readme.md
-
Training options (
ENC_DEC_train.py):--alpha: task loss weight (default 0.8)--pretrain_epoch: warmup epochs with MSE loss (default 0)compression_rate: inside script (default 0.3)
-
Image preprocessing:
- CIFAR-10 resized to 96×96, normalized to [-1, 1]
-
Checkpoints:
- Classifier →
google_net.pkl/google_net_final-lambda-XX.pkl - Semantic coder →
semantic_coder.pkl
- Classifier →
-
Outputs:
- Training →
images/(side-by-side reconstructions) - Testing →
images/snr{snr}/(per-SNR results + CSV logs)
- Training →
-
Adapting to other backbones:
- Replace encoder/decoder in
class SemanticNN(insideSemantIC.py) - Ensure
enc()outputs a quantized bitstream &dec()reconstructs inputs
- Replace encoder/decoder in
- Python 3.10–3.13
- PyTorch 1.13.0+
- torchvision
- numpy, scipy, numba
- pillow, imageio
- pandas
Install:
pip install -r requirements.txtThis project builds upon the following works and resources:
- Dataset: CIFAR-10 (used for training and evaluation)
- LDPC Implementation: adapted from pyldpc
- Semantic Training References:
This framework can be extended to other semantic backbones by modifying the SemanticNN class in SemantIC.py.
If you use this code, please cite:
@software{Khan_Semantic6G_2025,
author = {Md. Iqbal Haider Khan},
title = {Improving Information Quality in 6G Networks Using Semantic Auto-Encoders},
year = {2025},
url = {https://github.com/ihkokil/6G-Semantic-Communication},
note = {MIT License}
}MIT License © Md. Iqbal Haider Khan (@ihkokil)
See LICENSE for details.


