help@rskworld.in +91 93305 39277
RSK World
  • Home
  • Development
    • Web Development
    • Mobile Apps
    • Software
    • Games
    • Project
  • Technologies
    • Data Science
    • AI Development
    • Cloud Development
    • Blockchain
    • Cyber Security
    • Dev Tools
    • Testing Tools
  • Blog
  • About
  • Contact

Theme Settings

Color Scheme
Display Options
Font Size
100%
Back to Project
RSK World
pytorch-neuralnetworks
/
__pycache__
RSK World
pytorch-neuralnetworks
Neural networks with PyTorch
__pycache__
  • example.cpython-313.pyc3.4 KB
  • main.cpython-313.pyc4.7 KB
example.py
example.py
Raw Download
Find: Go to:
"""
Quick Start Example - PyTorch Neural Networks
Project: PyTorch Neural Networks
Author: RSK World
Website: https://rskworld.in
Email: help@rskworld.in
Phone: +91 93305 39277
Description: Quick example demonstrating PyTorch neural network basics
"""

import torch
import torch.nn as nn
import torch.optim as optim
from models.basic_nn import BasicNeuralNetwork
from training.utils import generate_sample_data, plot_training_history
from training.trainer import Trainer
from torch.utils.data import DataLoader, TensorDataset


def quick_example():
    """
    Quick example demonstrating a complete training workflow
    """
    print("=" * 60)
    print("PyTorch Neural Networks - Quick Start Example")
    print("Author: RSK World (https://rskworld.in)")
    print("=" * 60)
    
    # Set device
    device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
    print(f"\nUsing device: {device}\n")
    
    # Generate sample data
    print("Generating sample data...")
    X_train, y_train, X_test, y_test = generate_sample_data(
        n_samples=1000, n_features=20, n_classes=3
    )
    print(f"Training samples: {X_train.shape[0]}")
    print(f"Test samples: {X_test.shape[0]}\n")
    
    # Create data loaders
    train_dataset = TensorDataset(X_train, y_train)
    test_dataset = TensorDataset(X_test, y_test)
    train_loader = DataLoader(train_dataset, batch_size=32, shuffle=True)
    test_loader = DataLoader(test_dataset, batch_size=32, shuffle=False)
    
    # Create model
    print("Creating neural network model...")
    model = BasicNeuralNetwork(
        input_size=20,
        hidden_size=64,
        output_size=3,
        num_layers=2
    ).to(device)
    print(f"Model parameters: {sum(p.numel() for p in model.parameters())}\n")
    
    # Define loss and optimizer
    criterion = nn.CrossEntropyLoss()
    optimizer = optim.Adam(model.parameters(), lr=0.001)
    
    # Train model
    print("Starting training...")
    trainer = Trainer(model, criterion, optimizer, device)
    history = trainer.train(train_loader, test_loader, epochs=10)
    
    # Plot results
    print("\nGenerating training plots...")
    plot_training_history(history)
    
    print("\n" + "=" * 60)
    print("Example completed successfully!")
    print("=" * 60)


if __name__ == '__main__':
    quick_example()

78 lines•2.4 KB
python
🚀 Support RSK World

Subscribe to our YouTube channel for latest tutorials & updates!



Click subscribe & support our work ❤️

About RSK World

Founded by Molla Samser, with Designer & Tester Rima Khatun, RSK World is your one-stop destination for free programming resources, source code, and development tools.

Founder: Molla Samser
Designer & Tester: Rima Khatun

Development

  • Game Development
  • Web Development
  • Mobile Development
  • AI Development
  • Development Tools

Legal

  • Terms & Conditions
  • Privacy Policy
  • Disclaimer

Contact Info

Nutanhat, Mongolkote
Purba Burdwan, West Bengal
India, 713147

+91 93305 39277

hello@rskworld.in
support@rskworld.in

© 2026 RSK World. All rights reserved.

Content used for educational purposes only. View Disclaimer