Skip to content

A comprehensive guide and resource hub for learning PyTorch. Includes detailed explanations, hands-on examples, and best practices for mastering PyTorch, from basic tensor operations to advanced deep learning techniques.

Notifications You must be signed in to change notification settings

kambojvikram/Deep-Learning-with-PyTorch

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 

Repository files navigation

PyTorch Learning Repository

Welcome to the PyTorch Learning Repository! This repository serves as a comprehensive guide to PyTorch concepts, operations, and techniques, helping you master this powerful deep learning framework.


🔥 What is PyTorch?

PyTorch is an open-source machine learning framework that provides dynamic computation graphs, making it intuitive and flexible for building and training deep learning models. Its seamless integration with Python makes it a favorite among researchers and developers.


📚 Contents

  1. Getting Started
  2. Tensor Basics
  3. Tensor Manipulations
  4. Matrix Operations
  5. Tensor Indexing
  6. Broadcasting and Expanding
  7. Tensor Reduction
  8. Linear Algebra
  9. Comparison Operations
  10. Additional Resources

🚀 Getting Started

  1. Install PyTorch: Follow the official installation guide.

    # Example for Linux with CUDA
    pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118
  2. Import PyTorch:

    import torch

🧮 Tensor Basics

  • Creating Tensors:

    x = torch.tensor([1, 2, 3])  # 1D tensor
    y = torch.zeros(3, 3)        # 2D tensor
    z = torch.rand(3, 4)         # Random tensor
  • Inspecting Tensors:

    print(x.shape)       # Tensor shape
    print(x.dtype)       # Data type
    print(x.ndimension())  # Number of dimensions

🔄 Tensor Manipulations

  • Reshape: Change tensor shape.

    x = torch.arange(12).reshape(3, 4)  # (3, 4)
  • Squeeze/Unsqueeze: Remove or add dimensions of size 1.

    x = x.unsqueeze(0)  # Add a dimension
    x = x.squeeze()     # Remove dimensions of size 1
  • View: Similar to reshape but requires contiguous memory.

    x = x.view(3, 4)

🔢 Matrix Operations

  1. Matrix Multiplication:

    torch.mm(A, B)       # 2D matrix multiplication
    torch.matmul(A, B)   # Generalized matrix multiplication
  2. Batch Matrix Multiplication:

    torch.bmm(A, B)  # For 3D tensors

🔍 Tensor Indexing

  • Basic Indexing:

    x = torch.tensor([[1, 2], [3, 4]])
    print(x[0, 1])  # Access element
  • Advanced Indexing:

    indices = torch.tensor([0, 1])
    x_selected = torch.index_select(x, 0, indices)

↔️ Broadcasting and Expanding

  1. Expand: Expands dimensions without copying data.

    x = torch.tensor([1, 2, 3])
    x_expanded = x.unsqueeze(0).expand(2, 3)
  2. Repeat: Repeats data along dimensions.

    x_repeated = x.repeat(2, 1)

Tensor Reduction

  • Sum:

    torch.sum(x, dim=0)
  • Mean:

    torch.mean(x.float(), dim=1)
  • Product:

    torch.prod(x, dim=1)

📐 Linear Algebra

  • Matrix Inverse:

    torch.inverse(A)
  • SVD:

    torch.svd(A)
  • Eigenvalues:

    torch.eig(A, eigenvectors=True)

Comparison Operations

  1. Element-wise Comparison:

    torch.eq(A, B)  # Equal
    torch.gt(A, 2)  # Greater than
  2. Conditional Selection:

    torch.where(A > 2, A, B)

📖 Additional Resources


🤝 Contributing

Feel free to submit pull requests, report issues, or suggest improvements to this repository. Let’s make learning PyTorch easier for everyone!


📜 License

This repository is licensed under the MIT License. Feel free to use and modify it for educational purposes.

About

A comprehensive guide and resource hub for learning PyTorch. Includes detailed explanations, hands-on examples, and best practices for mastering PyTorch, from basic tensor operations to advanced deep learning techniques.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published