0% found this document useful (0 votes)
25 views2 pages

Img Proc

image processing
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views2 pages

Img Proc

image processing
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Cheatsheet: Computer Vision Skills, Machine Learning & Deep

Learning, Data Skills


Grok AI
September 2025

This cheatsheet is designed for gradual review. Each section includes key concepts, formulas/structures, and Python code examples
(using OpenCV, PyTorch, NumPy, etc.). Uses multicol for easy reading. Compile with pdflatex to create PDF.

1 Computer Vision Skills 1.4 Real-World Applications

- Robustness: Handle compression, resize. Use augmentation.


1.1 Basic Image Processing - Example: Resize and Crop

- Filters and Transformations: Use kernels import cv2


P for filtering (blur, 2
1
img = cv2 . imread ( ’ image . jpg ’)
sharpen). Formula: Convolution g(x, y) = f (i, j) · k(x − i, y − 3 resized = cv2 . resize ( img , (256 , 256) )
j). - Feature Analysis: Edges (Canny), corners (Harris). - 4 cropped = resized [50:200 , 50:200]
Example: Read and Filter Image (OpenCV) 5 cv2 . imwrite ( ’ processed . jpg ’ , cropped )

1 import cv2
2 img = cv2 . imread ( ’ image . jpg ’)
3 gray = cv2 . cvtColor ( img , cv2 . COLOR_ BGR2GR AY )
4 blurred = cv2 . GaussianBlur ( gray , (5 ,5) , 0)
5 cv2 . imwrite ( ’ blurred . jpg ’ , blurred ) 2 Machine Learning & Deep Learning

2.1 Building and Training Models

- Frameworks:PPyTorch/TensorFlow. Loss function: Cross-


Entropy L = − y log(ŷ). - Optimizers: Adam, SGD. Learn-
1.2 Synthetic Image Detection ing rate scheduler. - Example: Basic CNN Model (Py-
Torch)
- Real/Fake Classification: Use features like noise, texture.
Metrics: F1-Score = 2 · PPrecision+Recall
recision·Recall
. - Localization: Use 1 import torch . nn as nn
2 class SimpleCNN ( nn . Module ) :
segmentation to find manipulated regions (IoU = Overlap
U nion ). - 3 def __init__ ( self ) :
Example: Edge Detection (OpenCV) 4 super () . __init__ ()
5 self . conv1 = nn . Conv2d (3 , 16 , 3)
6 self . pool = nn . MaxPool2d (2 , 2)
1 import cv2 7 self . fc = nn . Linear (16*15*15 , 2) # Binary
2 img = cv2 . imread ( ’ image . jpg ’ , 0) class
3 edges = cv2 . Canny ( img , 100 , 200) 8 def forward ( self , x ) :
4 cv2 . imwrite ( ’ edges . jpg ’ , edges ) 9 x = self . pool ( F . relu ( self . conv1 ( x ) ) )
10 x = x . view ( -1 , 16*15*15)
11 return self . fc ( x )

1.3 Generative AI Models 2.2 CNN and Transformers Models

- GAN/Diffusion: Identify traces from StyleGAN, Stable Dif- - CNN Architectures: ResNet, EfficientNet. Residual block:
fusion. - Example: Generate Fake Image (PyTorch - Sim- y = F (x) + x. - Vision Transformers: Attention mechanism
T
ulated) Attention(Q, K, V ) = sof tmax( QK
√ )V . - Example: Train-
dk
ing CNN (PyTorch)
1 import torch
2 from torchvision import transforms 1 import torch . optim as optim
3 # Simulated diffusion model 2 model = SimpleCNN ()
4 transform = transforms . Compose ([ transforms . Resize (256) 3 optimizer = optim . Adam ( model . parameters () , lr =0.001)
]) 4 loss_fn = nn . C r o s s E n t r o p y L o s s ()
5 # Use pre - trained model ( e . g . , Stable Diffusion ) 5 # Training loop : for epoch in range (10) : ...
2.3 Model Evaluation 3.3 Handling Large Data
- Metrics: Accuracy, Precision, Recall, ROC AUC, EER. - Ro- - Big Data Tools: Dataloader in PyTorch for batching. - Ex-
bustness: Test with adversarial examples. - Example: Cal- ample: DataLoader (PyTorch)
culate F1-Score (Scikit-learn) 1 from torch . utils . data import DataLoader

1 from sklearn . metrics import f1_score 2 dataloader = DataLoader ( dataset , batch_size =32 ,
2 y_true = [0 , 1 , 1 , 0] shuffle = True )
3 y_pred = [0 , 1 , 0 , 0] 3 for images , labels in dataloader :
4 f1 = f1_score ( y_true , y_pred ) 4 # Training ...
5 print ( f1 ) # Output : 0.5

3.4 Error Analysis and Improvement


2.4 Handling Imbalanced Data
- Analysis: Confusion matrix, error analysis. - Example:
- Techniques: Oversampling, undersampling, SMOTE. - Ex- Confusion Matrix (Scikit-learn)
ample: Oversampling (Imbalanced-learn)
1 from sklearn . metrics import c o n f u s i o n _ m a t r i x
1 from imblearn . over_sampling import R a n d o m O v e r S a m p l e r 2 cm = c o n f u s i o n _ m a t r i x ( y_true , y_pred )
2 ros = R a n d o m O v e r S a m p l e r () 3 print ( cm )
3 X_res , y_res = ros . fit_resample (X , y )

3 Data Skills
3.1 Data Management and Preprocessing
- Cleaning: Handle missing values, outliers. Normalization:
x′ = x−µ
σ . - Data Augmentation: Rotate, flip for images. -
Example: Preprocessing with Pandas and NumPy
1 import pandas as pd
2 import numpy as np
3 df = pd . read_csv ( ’ data . csv ’)
4 df . fillna (0 , inplace = True ) # Handle missing
5 normalized = ( df - df . mean () ) / df . std ()

3.2 Using Open Data


- Integrating Datasets: LAION, RAISE. Data transparency.
- Handling "In-the-wild": Data from social media with vari-
ations. - Example: Load and Augment Images (Torchvi-
sion)
1 from torchvision import datasets , transforms
2 transform = transforms . Compose ([
3 transforms . Ra ndomRo tation (30) ,
4 transforms . R a n d o m H o r i z o n t a l F l i p () ,
5 transforms . ToTensor ()
6 ])
7 dataset = datasets . ImageFolder ( ’ path / to / data ’ ,
transform = transform )

You might also like