12/28/2024

Fashion ai dataset.

 ModaNet (2018) was groundbreaking but there have been several more recent datasets and models for fashion segmentation and analysis. Here are some notable recent ones:

DeepFashion2 (2023 Update)

  • 491K images with 801K clothing items
  • 13 clothes categories (similar to ModaNet)
  • More detailed annotations including style, occlusion, zoom-in
  • Higher quality annotations and more diverse images
  • Link: https://github.com/switchablenorms/DeepFashion2

VITON-HD (2022)

  • High resolution virtual try-on dataset
  • 13,679 front-view woman/clothing image pairs
  • High quality segmentation masks
  • Particularly good for virtual try-on applications

FashionAI Dataset (2023)

  • From Alibaba
  • Over 180K images
  • Focus on attribute recognition
  • Detailed hierarchical attribute annotations
  • More modern fashion styles and better image quality

LIP (Look Into Person) Dataset (2022 version)

  • 50,000 images with pixel-level annotations
  • 19 semantic human part labels
  • Multiple viewpoints and poses
  • Human parsing focused but includes detailed clothing segmentation

ACGPN Dataset (2023)

  • 40,000 high-resolution person images
  • Detailed parsing maps
  • Semantic segmentation for clothes
  • Focuses on both parsing and virtual try-on

Key Improvements in Recent Datasets:

  1. Higher resolution images
  2. Better annotation quality
  3. More diverse poses and viewpoints
  4. More modern fashion styles
  5. Better handling of occlusion and layering
  6. More detailed attribute annotations
  7. Multi-task annotations (segmentation + attributes + landmarks)

For your specific use case, I would recommend:

  1. DeepFashion2 as your primary dataset - it's the most comprehensive and recent
  2. Augment with ACGPN if you need higher resolution images
  3. Consider FashionAI if you need very detailed attribute recognition

"fashion attribute recognition" or "clothing parsing"

 AI model for clothing analysis and attribute extraction from person images. This is often called "fashion attribute recognition" or "clothing parsing" in computer vision.

For this task, you'll want to consider several components:

  1. Person/Clothing Segmentation
  • First, you'll need to segment different clothing items
  • Models like DeepFashion2 or ModaNet provide good architectures for this
  • You can use Mask R-CNN or similar instance segmentation models as a base
  1. Attribute Recognition For each segmented clothing item, you'll need to recognize:
  • Category (top, pants, hat, etc.)
  • Color
  • Material
  • Pattern
  • Style/type
  • Specific attributes (collar type, sleeve length, etc.)

Available Datasets:

  1. DeepFashion Dataset
  • Over 800,000 images
  • 50 clothing categories
  • Multiple attributes per item
  • Includes landmarks and segmentation
  • Good for both segmentation and attribute recognition
  1. ModaNet
  • About 55,000 fully annotated images
  • 13 clothing categories
  • Instance segmentation masks
  • Strong street-style focus
  1. Fashion-MNIST
  • Simpler dataset, good for initial testing
  • 70,000 grayscale images
  • 10 clothing categories
  • Limited attributes
  1. Clothing Co-Parsing (CCP) Dataset
  • 2,098 fashion images
  • 59 clothing categories
  • Pixel-level annotations
  • Good for fine-grained parsing

Recommended Approach:

  1. Model Architecture:
  • Use a two-stage approach: a. First stage: Mask R-CNN or YOLOv8 for segmentation b. Second stage: ResNet or EfficientNet backbone with attribute-specific heads
  1. Training Strategy:
  • Pre-train on large datasets like DeepFashion
  • Fine-tune on your specific use case
  • Use multi-task learning for different attributes
  1. Implementation Frameworks:
  • PyTorch or TensorFlow
  • Consider using MMFashion (open-source fashion analysis toolbox)
  • HuggingFace Transformers for recent vision models

12/25/2024

Installing cuDNN on Ubuntu 22.04

 

Installing cuDNN on Ubuntu 22.04

Step 1: Download cuDNN

  1. Go to https://developer.nvidia.com/cudnn
  2. Sign in to your NVIDIA Developer account (or create one if needed)
  3. Navigate to Downloads
  4. Find and download cuDNN v9.6.0 for Ubuntu 22.04 (.deb package)

Step 2: Install cuDNN

Run these commands in order:

# Install the downloaded package sudo dpkg -i cudnn-local-repo-ubuntu2204-9.6.0_1.0-1_amd64.deb # Copy the keyring sudo cp /var/cudnn-local-repo-ubuntu2204-9.6.0/cudnn-*-keyring.gpg /usr/share/keyrings/ # Update package list sudo apt-get update # Install cuDNN sudo apt-get -y install cudnn # Install CUDA 12 specific package sudo apt-get -y install cudnn-cuda-12

Step 3: Verify Installation

# Check if cuDNN is installed correctly find /usr -name "libcudnn.so*"

Note: Direct download links won't work - you must download through NVIDIA's website after logging in.

12/11/2024

Pedestrian and human attribute dataset.

 

For Pedestrian Detection:

  1. CityPersons - High-quality pedestrian detection dataset with diverse urban scenes from multiple European cities
  2. Caltech Pedestrian Dataset - Contains approximately 250,000 frames with 350,000 bounding boxes and 2,300 unique pedestrians
  3. INRIA Person Dataset - Includes full-body pedestrians in various poses and backgrounds
  4. MOT (Multiple Object Tracking) Dataset - Contains pedestrians in crowded scenes

For Human Attribute Analysis:

  1. RAP (Richly Annotated Pedestrian) Dataset - Over 40 attributes including clothing types, colors, and accessories
  2. PETA Dataset - Large-scale surveillance person attribute dataset with 19,000 images
  3. Market-1501 Attribute Dataset - Contains 27 attributes for clothing and personal items
  4. DeepFashion Dataset - Focuses on clothing items with detailed annotations

Some considerations when choosing a dataset:

  • Make sure to check the license terms for each dataset
  • Consider the image quality and diversity needed for your specific use case
  • Check if the annotations match your requirements (bounding boxes, attributes, etc.)
  • Verify that the dataset size is sufficient for your model training needs

11/19/2024

Print detail Model structure

Refer to code

..

def print_model_structure(model, indent=0):
for name, child in model.named_children():
print(' ' * indent + f'└─ {name}: {child.__class__.__name__}')
if list(child.children()):
print_model_structure(child, indent + 2)

print_model_structure(composer_model)

..


This is Llama 3.1 8b Model Structure

└─ model: LlamaForCausalLM
└─ model: LlamaModel
└─ embed_tokens: Embedding
└─ layers: ModuleList
└─ 0: LlamaDecoderLayer
└─ self_attn: LlamaFlashAttention2
└─ q_proj: Linear
└─ k_proj: Linear
└─ v_proj: Linear
└─ o_proj: Linear
└─ rotary_emb: LlamaRotaryEmbedding
└─ mlp: LlamaMLP
└─ gate_proj: Linear
└─ up_proj: Linear
└─ down_proj: Linear
└─ act_fn: SiLU
└─ input_layernorm: LlamaRMSNorm
└─ post_attention_layernorm: LlamaRMSNorm
└─ 1: LlamaDecoderLayer
└─ self_attn: LlamaFlashAttention2
└─ q_proj: Linear
└─ k_proj: Linear
└─ v_proj: Linear
└─ o_proj: Linear
└─ rotary_emb: LlamaRotaryEmbedding
└─ mlp: LlamaMLP
└─ gate_proj: Linear
└─ up_proj: Linear
└─ down_proj: Linear
└─ act_fn: SiLU
└─ input_layernorm: LlamaRMSNorm
└─ post_attention_layernorm: LlamaRMSNorm
└─ 2: LlamaDecoderLayer
└─ self_attn: LlamaFlashAttention2
└─ q_proj: Linear
└─ k_proj: Linear
└─ v_proj: Linear
└─ o_proj: Linear
└─ rotary_emb: LlamaRotaryEmbedding
└─ mlp: LlamaMLP
└─ gate_proj: Linear
└─ up_proj: Linear
└─ down_proj: Linear
└─ act_fn: SiLU
└─ input_layernorm: LlamaRMSNorm
└─ post_attention_layernorm: LlamaRMSNorm
└─ 3: LlamaDecoderLayer
└─ self_attn: LlamaFlashAttention2
└─ q_proj: Linear
└─ k_proj: Linear
└─ v_proj: Linear
└─ o_proj: Linear
└─ rotary_emb: LlamaRotaryEmbedding
└─ mlp: LlamaMLP
└─ gate_proj: Linear
└─ up_proj: Linear
└─ down_proj: Linear
└─ act_fn: SiLU
└─ input_layernorm: LlamaRMSNorm
└─ post_attention_layernorm: LlamaRMSNorm
└─ 4: LlamaDecoderLayer
└─ self_attn: LlamaFlashAttention2
└─ q_proj: Linear
└─ k_proj: Linear
└─ v_proj: Linear
└─ o_proj: Linear
└─ rotary_emb: LlamaRotaryEmbedding
└─ mlp: LlamaMLP
└─ gate_proj: Linear
└─ up_proj: Linear
└─ down_proj: Linear
└─ act_fn: SiLU
└─ input_layernorm: LlamaRMSNorm
└─ post_attention_layernorm: LlamaRMSNorm
└─ 5: LlamaDecoderLayer
└─ self_attn: LlamaFlashAttention2
└─ q_proj: Linear
└─ k_proj: Linear
└─ v_proj: Linear
└─ o_proj: Linear
└─ rotary_emb: LlamaRotaryEmbedding
└─ mlp: LlamaMLP
└─ gate_proj: Linear
└─ up_proj: Linear
└─ down_proj: Linear
└─ act_fn: SiLU
└─ input_layernorm: LlamaRMSNorm
└─ post_attention_layernorm: LlamaRMSNorm
└─ 6: LlamaDecoderLayer
└─ self_attn: LlamaFlashAttention2
└─ q_proj: Linear
└─ k_proj: Linear
└─ v_proj: Linear
└─ o_proj: Linear
└─ rotary_emb: LlamaRotaryEmbedding
└─ mlp: LlamaMLP
└─ gate_proj: Linear
└─ up_proj: Linear
└─ down_proj: Linear
└─ act_fn: SiLU
└─ input_layernorm: LlamaRMSNorm
└─ post_attention_layernorm: LlamaRMSNorm
└─ 7: LlamaDecoderLayer
└─ self_attn: LlamaFlashAttention2
└─ q_proj: Linear
└─ k_proj: Linear
└─ v_proj: Linear
└─ o_proj: Linear
└─ rotary_emb: LlamaRotaryEmbedding
└─ mlp: LlamaMLP
└─ gate_proj: Linear
└─ up_proj: Linear
└─ down_proj: Linear
└─ act_fn: SiLU
└─ input_layernorm: LlamaRMSNorm
└─ post_attention_layernorm: LlamaRMSNorm
└─ 8: LlamaDecoderLayer
└─ self_attn: LlamaFlashAttention2
└─ q_proj: Linear
└─ k_proj: Linear
└─ v_proj: Linear
└─ o_proj: Linear
└─ rotary_emb: LlamaRotaryEmbedding
└─ mlp: LlamaMLP
└─ gate_proj: Linear
└─ up_proj: Linear
└─ down_proj: Linear
└─ act_fn: SiLU
└─ input_layernorm: LlamaRMSNorm
└─ post_attention_layernorm: LlamaRMSNorm
└─ 9: LlamaDecoderLayer
└─ self_attn: LlamaFlashAttention2
└─ q_proj: Linear
└─ k_proj: Linear
└─ v_proj: Linear
└─ o_proj: Linear
└─ rotary_emb: LlamaRotaryEmbedding
└─ mlp: LlamaMLP
└─ gate_proj: Linear
└─ up_proj: Linear
└─ down_proj: Linear
└─ act_fn: SiLU
└─ input_layernorm: LlamaRMSNorm
└─ post_attention_layernorm: LlamaRMSNorm
└─ 10: LlamaDecoderLayer
└─ self_attn: LlamaFlashAttention2
└─ q_proj: Linear
└─ k_proj: Linear
└─ v_proj: Linear
└─ o_proj: Linear
└─ rotary_emb: LlamaRotaryEmbedding
└─ mlp: LlamaMLP
└─ gate_proj: Linear
└─ up_proj: Linear
└─ down_proj: Linear
└─ act_fn: SiLU
└─ input_layernorm: LlamaRMSNorm
└─ post_attention_layernorm: LlamaRMSNorm
└─ 11: LlamaDecoderLayer
└─ self_attn: LlamaFlashAttention2
└─ q_proj: Linear
└─ k_proj: Linear
└─ v_proj: Linear
└─ o_proj: Linear
└─ rotary_emb: LlamaRotaryEmbedding
└─ mlp: LlamaMLP
└─ gate_proj: Linear
└─ up_proj: Linear
└─ down_proj: Linear
└─ act_fn: SiLU
└─ input_layernorm: LlamaRMSNorm
└─ post_attention_layernorm: LlamaRMSNorm
└─ 12: LlamaDecoderLayer
└─ self_attn: LlamaFlashAttention2
└─ q_proj: Linear
└─ k_proj: Linear
└─ v_proj: Linear
└─ o_proj: Linear
└─ rotary_emb: LlamaRotaryEmbedding
└─ mlp: LlamaMLP
└─ gate_proj: Linear
└─ up_proj: Linear
└─ down_proj: Linear
└─ act_fn: SiLU
└─ input_layernorm: LlamaRMSNorm
└─ post_attention_layernorm: LlamaRMSNorm
└─ 13: LlamaDecoderLayer
└─ self_attn: LlamaFlashAttention2
└─ q_proj: Linear
└─ k_proj: Linear
└─ v_proj: Linear
└─ o_proj: Linear
└─ rotary_emb: LlamaRotaryEmbedding
└─ mlp: LlamaMLP
└─ gate_proj: Linear
└─ up_proj: Linear
└─ down_proj: Linear
└─ act_fn: SiLU
└─ input_layernorm: LlamaRMSNorm
└─ post_attention_layernorm: LlamaRMSNorm
└─ 14: LlamaDecoderLayer
└─ self_attn: LlamaFlashAttention2
└─ q_proj: Linear
└─ k_proj: Linear
└─ v_proj: Linear
└─ o_proj: Linear
└─ rotary_emb: LlamaRotaryEmbedding
└─ mlp: LlamaMLP
└─ gate_proj: Linear
└─ up_proj: Linear
└─ down_proj: Linear
└─ act_fn: SiLU
└─ input_layernorm: LlamaRMSNorm
└─ post_attention_layernorm: LlamaRMSNorm
└─ 15: LlamaDecoderLayer
└─ self_attn: LlamaFlashAttention2
└─ q_proj: Linear
└─ k_proj: Linear
└─ v_proj: Linear
└─ o_proj: Linear
└─ rotary_emb: LlamaRotaryEmbedding
└─ mlp: LlamaMLP
└─ gate_proj: Linear
└─ up_proj: Linear
└─ down_proj: Linear
└─ act_fn: SiLU
└─ input_layernorm: LlamaRMSNorm
└─ post_attention_layernorm: LlamaRMSNorm
└─ 16: LlamaDecoderLayer
└─ self_attn: LlamaFlashAttention2
└─ q_proj: Linear
└─ k_proj: Linear
└─ v_proj: Linear
└─ o_proj: Linear
└─ rotary_emb: LlamaRotaryEmbedding
└─ mlp: LlamaMLP
└─ gate_proj: Linear
└─ up_proj: Linear
└─ down_proj: Linear
└─ act_fn: SiLU
└─ input_layernorm: LlamaRMSNorm
└─ post_attention_layernorm: LlamaRMSNorm
└─ 17: LlamaDecoderLayer
└─ self_attn: LlamaFlashAttention2
└─ q_proj: Linear
└─ k_proj: Linear
└─ v_proj: Linear
└─ o_proj: Linear
└─ rotary_emb: LlamaRotaryEmbedding
└─ mlp: LlamaMLP
└─ gate_proj: Linear
└─ up_proj: Linear
└─ down_proj: Linear
└─ act_fn: SiLU
└─ input_layernorm: LlamaRMSNorm
└─ post_attention_layernorm: LlamaRMSNorm
└─ 18: LlamaDecoderLayer
└─ self_attn: LlamaFlashAttention2
└─ q_proj: Linear
└─ k_proj: Linear
└─ v_proj: Linear
└─ o_proj: Linear
└─ rotary_emb: LlamaRotaryEmbedding
└─ mlp: LlamaMLP
└─ gate_proj: Linear
└─ up_proj: Linear
└─ down_proj: Linear
└─ act_fn: SiLU
└─ input_layernorm: LlamaRMSNorm
└─ post_attention_layernorm: LlamaRMSNorm
└─ 19: LlamaDecoderLayer
└─ self_attn: LlamaFlashAttention2
└─ q_proj: Linear
└─ k_proj: Linear
└─ v_proj: Linear
└─ o_proj: Linear
└─ rotary_emb: LlamaRotaryEmbedding
└─ mlp: LlamaMLP
└─ gate_proj: Linear
└─ up_proj: Linear
└─ down_proj: Linear
└─ act_fn: SiLU
└─ input_layernorm: LlamaRMSNorm
└─ post_attention_layernorm: LlamaRMSNorm
└─ 20: LlamaDecoderLayer
└─ self_attn: LlamaFlashAttention2
└─ q_proj: Linear
└─ k_proj: Linear
└─ v_proj: Linear
└─ o_proj: Linear
└─ rotary_emb: LlamaRotaryEmbedding
└─ mlp: LlamaMLP
└─ gate_proj: Linear
└─ up_proj: Linear
└─ down_proj: Linear
└─ act_fn: SiLU
└─ input_layernorm: LlamaRMSNorm
└─ post_attention_layernorm: LlamaRMSNorm
└─ 21: LlamaDecoderLayer
└─ self_attn: LlamaFlashAttention2
└─ q_proj: Linear
└─ k_proj: Linear
└─ v_proj: Linear
└─ o_proj: Linear
└─ rotary_emb: LlamaRotaryEmbedding
└─ mlp: LlamaMLP
└─ gate_proj: Linear
└─ up_proj: Linear
└─ down_proj: Linear
└─ act_fn: SiLU
└─ input_layernorm: LlamaRMSNorm
└─ post_attention_layernorm: LlamaRMSNorm
└─ 22: LlamaDecoderLayer
└─ self_attn: LlamaFlashAttention2
└─ q_proj: Linear
└─ k_proj: Linear
└─ v_proj: Linear
└─ o_proj: Linear
└─ rotary_emb: LlamaRotaryEmbedding
└─ mlp: LlamaMLP
└─ gate_proj: Linear
└─ up_proj: Linear
└─ down_proj: Linear
└─ act_fn: SiLU
└─ input_layernorm: LlamaRMSNorm
└─ post_attention_layernorm: LlamaRMSNorm
└─ 23: LlamaDecoderLayer
└─ self_attn: LlamaFlashAttention2
└─ q_proj: Linear
└─ k_proj: Linear
└─ v_proj: Linear
└─ o_proj: Linear
└─ rotary_emb: LlamaRotaryEmbedding
└─ mlp: LlamaMLP
└─ gate_proj: Linear
└─ up_proj: Linear
└─ down_proj: Linear
└─ act_fn: SiLU
└─ input_layernorm: LlamaRMSNorm
└─ post_attention_layernorm: LlamaRMSNorm
└─ 24: LlamaDecoderLayer
└─ self_attn: LlamaFlashAttention2
└─ q_proj: Linear
└─ k_proj: Linear
└─ v_proj: Linear
└─ o_proj: Linear
└─ rotary_emb: LlamaRotaryEmbedding
└─ mlp: LlamaMLP
└─ gate_proj: Linear
└─ up_proj: Linear
└─ down_proj: Linear
└─ act_fn: SiLU
└─ input_layernorm: LlamaRMSNorm
└─ post_attention_layernorm: LlamaRMSNorm
└─ 25: LlamaDecoderLayer
└─ self_attn: LlamaFlashAttention2
└─ q_proj: Linear
└─ k_proj: Linear
└─ v_proj: Linear
└─ o_proj: Linear
└─ rotary_emb: LlamaRotaryEmbedding
└─ mlp: LlamaMLP
└─ gate_proj: Linear
└─ up_proj: Linear
└─ down_proj: Linear
└─ act_fn: SiLU
└─ input_layernorm: LlamaRMSNorm
└─ post_attention_layernorm: LlamaRMSNorm
└─ 26: LlamaDecoderLayer
└─ self_attn: LlamaFlashAttention2
└─ q_proj: Linear
└─ k_proj: Linear
└─ v_proj: Linear
└─ o_proj: Linear
└─ rotary_emb: LlamaRotaryEmbedding
└─ mlp: LlamaMLP
└─ gate_proj: Linear
└─ up_proj: Linear
└─ down_proj: Linear
└─ act_fn: SiLU
└─ input_layernorm: LlamaRMSNorm
└─ post_attention_layernorm: LlamaRMSNorm
└─ 27: LlamaDecoderLayer
└─ self_attn: LlamaFlashAttention2
└─ q_proj: Linear
└─ k_proj: Linear
└─ v_proj: Linear
└─ o_proj: Linear
└─ rotary_emb: LlamaRotaryEmbedding
└─ mlp: LlamaMLP
└─ gate_proj: Linear
└─ up_proj: Linear
└─ down_proj: Linear
└─ act_fn: SiLU
└─ input_layernorm: LlamaRMSNorm
└─ post_attention_layernorm: LlamaRMSNorm
└─ 28: LlamaDecoderLayer
└─ self_attn: LlamaFlashAttention2
└─ q_proj: Linear
└─ k_proj: Linear
└─ v_proj: Linear
└─ o_proj: Linear
└─ rotary_emb: LlamaRotaryEmbedding
└─ mlp: LlamaMLP
└─ gate_proj: Linear
└─ up_proj: Linear
└─ down_proj: Linear
└─ act_fn: SiLU
└─ input_layernorm: LlamaRMSNorm
└─ post_attention_layernorm: LlamaRMSNorm
└─ 29: LlamaDecoderLayer
└─ self_attn: LlamaFlashAttention2
└─ q_proj: Linear
└─ k_proj: Linear
└─ v_proj: Linear
└─ o_proj: Linear
└─ rotary_emb: LlamaRotaryEmbedding
└─ mlp: LlamaMLP
└─ gate_proj: Linear
└─ up_proj: Linear
└─ down_proj: Linear
└─ act_fn: SiLU
└─ input_layernorm: LlamaRMSNorm
└─ post_attention_layernorm: LlamaRMSNorm
└─ 30: LlamaDecoderLayer
└─ self_attn: LlamaFlashAttention2
└─ q_proj: Linear
└─ k_proj: Linear
└─ v_proj: Linear
└─ o_proj: Linear
└─ rotary_emb: LlamaRotaryEmbedding
└─ mlp: LlamaMLP
└─ gate_proj: Linear
└─ up_proj: Linear
└─ down_proj: Linear
└─ act_fn: SiLU
└─ input_layernorm: LlamaRMSNorm
└─ post_attention_layernorm: LlamaRMSNorm
└─ 31: LlamaDecoderLayer
└─ self_attn: LlamaFlashAttention2
└─ q_proj: Linear
└─ k_proj: Linear
└─ v_proj: Linear
└─ o_proj: Linear
└─ rotary_emb: LlamaRotaryEmbedding
└─ mlp: LlamaMLP
└─ gate_proj: Linear
└─ up_proj: Linear
└─ down_proj: Linear
└─ act_fn: SiLU
└─ input_layernorm: LlamaRMSNorm
└─ post_attention_layernorm: LlamaRMSNorm
└─ norm: LlamaRMSNorm
└─ rotary_emb: LlamaRotaryEmbedding
└─ lm_head: Linear

11/17/2024

Hook Llama 3.1 8b layer and print dimension

 refer to code


.

def register_dimension_hooks(model, rank):
if rank != 0:
return
print('\n------------------- Model Structure -------------------')
print("Model type:", type(model))
# Get the actual model through the wrapper layers
if hasattr(model, 'model'):
model = model.model
if hasattr(model, 'model'):
model = model.model
print("Base model type:", type(model))
def make_hook(name, rank):
def hook(module, input, output):
print(f"\n--------------- Hook: {name} ---------------")
if hasattr(module, 'weight'):
weight = module.weight
print(f"GPU {rank} - {name}:")
print(f"Input shape: {input[0].shape}")
if hasattr(weight, '_local_tensor'):
local_weight = weight._local_tensor
print(f"Local weight shape: {local_weight.shape}")
print(f"Global weight shape: {weight.shape}")
if hasattr(weight, 'device_mesh'):
print(f"Device mesh: {weight.device_mesh}")
print(f"Placement: {weight.placements}")
print(f"Output shape: {output.shape}")
print("-" * 50)
return hook

# Register hooks for embedding layer
if hasattr(model, 'embed_tokens'):
print("Found embed_tokens")
model.embed_tokens.register_forward_hook(make_hook('embed_tokens', rank))

# Register hooks for all transformer layers
if hasattr(model, 'layers'):
for i, layer in enumerate(model.layers):
# Attention blocks
layer.self_attn.q_proj.register_forward_hook(
make_hook(f'layer_{i}_q_proj', rank))
layer.self_attn.k_proj.register_forward_hook(
make_hook(f'layer_{i}_k_proj', rank))
layer.self_attn.v_proj.register_forward_hook(
make_hook(f'layer_{i}_v_proj', rank))
layer.self_attn.o_proj.register_forward_hook(
make_hook(f'layer_{i}_o_proj', rank))
# MLP blocks
layer.mlp.gate_proj.register_forward_hook(
make_hook(f'layer_{i}_mlp_gate_proj', rank))
layer.mlp.up_proj.register_forward_hook(
make_hook(f'layer_{i}_mlp_up_proj', rank))
layer.mlp.down_proj.register_forward_hook(
make_hook(f'layer_{i}_mlp_down_proj', rank))
# Layer norms
layer.input_layernorm.register_forward_hook(
make_hook(f'layer_{i}_input_layernorm', rank))
layer.post_attention_layernorm.register_forward_hook(
make_hook(f'layer_{i}_post_attention_layernorm', rank))

# Register hook for final layer norm
if hasattr(model, 'norm'):
model.norm.register_forward_hook(make_hook('final_layernorm', rank))

# Register hook for LM head
if hasattr(model, 'lm_head'):
print("Found lm_head")
model.lm_head.register_forward_hook(make_hook('lm_head', rank))

# Print model structure to debug
print("\nModel attributes:", dir(model))

..


Thank you.


11/03/2024

Auto Number Plate Recognition (ANPR), SDK source code



 # install 

pip install marearts-anpr


# code

# pip install marearts-anpr
import cv2
from PIL import Image
from marearts_anpr import ma_anpr_detector
from marearts_anpr import ma_anpr_ocr
from marearts_anpr import marearts_anpr_from_pil
from marearts_anpr import marearts_anpr_from_image_file
from marearts_anpr import marearts_anpr_from_cv2
if __name__ == '__main__':
#################################
## Initiate MareArts ANPR
print("EU ANPR")
user_name = "your_email"
serial_key = "your_serial_key"
detector_model_version = "middle" # Options: refer to detector model table
ocr_model_version = "eu" # Options: refer to ocr model table
# MareArts ANPR Detector Inference
anpr_d = ma_anpr_detector(detector_model_version, user_name, serial_key, conf_thres=0.3, iou_thres=0.5)
# MareArts ANPR OCR Inference
anpr_r = ma_anpr_ocr(ocr_model_version, user_name, serial_key)
#################################
#################################
# Routine Task 1 - Predict from File
image_path = './sample_images/eu_test1.jpg'
output = marearts_anpr_from_image_file(anpr_d, anpr_r, image_path)
print(output)
# Routine Task 2 - Predict from cv2
img = cv2.imread(image_path)
output = marearts_anpr_from_cv2(anpr_d, anpr_r, img)
print(output)
# Routine Task 3 - Predict from Pillow
pil_img = Image.open(image_path)
output = marearts_anpr_from_pil(anpr_d, anpr_r, pil_img)
print(output)
#################################
#################################
## Initiate MareArts ANPR for Korea
print("ANPR Korean")
# user_name, serial_key are already defined
# anpr_d is also already initiated before
ocr_model_version = "kr"
# MareArts ANPR OCR Inference
anpr_r = ma_anpr_ocr(ocr_model_version, user_name, serial_key)
#################################
# Routine Task 1 - Predict from File
image_path = './sample_images/kr_test2.jpg'
output = marearts_anpr_from_image_file(anpr_d, anpr_r, image_path)
print(output)
# Routine Task 2 - Predict from cv2
img = cv2.imread(image_path)
output = marearts_anpr_from_cv2(anpr_d, anpr_r, img)
print(output)
# Routine Task 3 - Predict from Pillow
pil_img = Image.open(image_path)
output = marearts_anpr_from_pil(anpr_d, anpr_r, pil_img)
print(output)
#################################

..


# Ask license is here: https://study.marearts.com/p/anpr-lpr-solution.html

# Live Test is here: https://live.marearts.com