NeT2i (Network to Image) converts network traffic data into RGB images suitable for CNN-based anomaly detection.
Project description
NeT2I - Network to Image
NeT2I (Network to Image) is a Python tool for converting structured network traffic data into RGB images that can be used for anomaly detection via Convolutional Neural Networks (CNNs). It supports CSV inputs containing IP addresses, MAC addresses, numeric values, and string fields. These are automatically detected, processed, and encoded into image representations.
🔍 Key Features
- Converts CSV-based network traffic into RGB images
- Handles MAC addresses, IP addresses, integers, floats, and strings
- Encodes numeric data using IEEE 754 float-to-byte representation for lossless recovery
- Outputs RGB images for CNN model training or anomaly detection tasks
- Includes type detection, data normalization, and image generation
📦 Requirements
Install the dependencies using:
pip install pillow numpy pandas
🚀 Getting Started
1. Prepare Your Data
Place your CSV file in the working directory and rename it to:
source_in2.csv
Each row in this file should represent one sample of network data. No headers are expected.
2. Run the Script
python net2i.py
This will:
- Detect and map each column to its correct type (IP, MAC, float, etc.)
- Convert each row into two RGB pixels per float-equivalent value
- Create one
.pngimage per row in thedata/directory - Generate a
data_types.jsonfile for decoding and debugging
🧠 How It Works
- MAC Addresses are split into two hexadecimal chunks and treated as large integers.
- IP Addresses are split into four octets, each converted to float.
- Integers are first cast to float before encoding to RGB using
struct.pack(), preserving their IEEE 754 byte format. - Strings are hashed to integers, then converted to floats and encoded similarly.
Each float is encoded into two RGB pixels (6 bytes) to avoid information loss.
📁 Output Structure
data/: Directory containing all generated RGB images (one per row)data_types.json: Contains original and final column types after preprocessingfrom_image.csv: Placeholder file for reverse decoding (optional, not yet included)
🧪 Example Use Case
Once converted, these RGB images can be fed into CNN models like ResNet, VGG, or custom classifiers for anomaly detection, intrusion detection, or network behavior classification tasks.
🛠️ Configuration
You can adjust these options at the top of the script:
INPUT_CSV = "source_in2.csv"
OUTPUT_DIR = "data"
IMAGE_SIZE = 150
TYPES_FILE = "data_types.json"
DECODED = "from_image.csv"
💡 Usage Examples
Basic Usage
import NeT2i.converter as converter
# Simple conversion
results = converter.load_csv('source_in2.csv')
print(f"Generated {results['num_images']} images")
Advanced Usage with Custom Parameters
import NeT2i.converter as converter
# Custom configuration
results = converter.load_csv(
'source_in2.csv',
output_dir='my_images',
image_size=150,
types_file='my_types.json',
clean_existing=True
)
# Access results
print(f"Original CSV shape: {results['original_shape']}")
print(f"Detected types: {results['original_types']}")
print(f"Final types after splitting: {results['final_types']}")
Object-Oriented Usage
from NeT2i.converter import NeT2iConverter
# Create converter instance with custom settings
converter = NeT2iConverter(
output_dir='data_images',
image_size=150,
clean_existing=True
)
# Convert multiple files
results1 = converter.load_csv('file1.csv')
results2 = converter.load_csv('file2.csv')
🧾 License
This project is licensed under the MIT License.
👥 Authors
🌐 Project Links
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file net2i-2.0.1.tar.gz.
File metadata
- Download URL: net2i-2.0.1.tar.gz
- Upload date:
- Size: 9.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
395b4102ae6b42291d0f083d2e80f49cd679aec409090f2decebc0f267917e78
|
|
| MD5 |
3364593f28918d9e1a0100c6497111ab
|
|
| BLAKE2b-256 |
c33e27095fd541dfa57c82d14f8123062d43f6d517c96e42ff601560fc477708
|
File details
Details for the file net2i-2.0.1-py3-none-any.whl.
File metadata
- Download URL: net2i-2.0.1-py3-none-any.whl
- Upload date:
- Size: 8.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3a87b5c1f71e0653dda65f386a78f7a3b1bfaffba67880aebfca87bd59f689d8
|
|
| MD5 |
c4a69b5856562be8b613e304e160675c
|
|
| BLAKE2b-256 |
45a9d1bea1c951490e177aa8ecef50f1ba23c1f89d0132d2d2196f640986dbfe
|