File size: 1,659 Bytes
8900f0a
 
 
 
 
 
 
 
 
15dba6b
 
8900f0a
 
 
 
 
 
 
 
15dba6b
8900f0a
 
 
 
15dba6b
8900f0a
 
 
 
 
 
 
 
 
 
 
15dba6b
 
8900f0a
 
15dba6b
 
 
 
 
 
 
8900f0a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# config.py

import os

# --- Paths ---
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
DATA_DIR = os.path.join(BASE_DIR, 'data')
MODELS_DIR = os.path.join(BASE_DIR, 'models')

TRAIN_IMAGES_DIR = os.path.join(DATA_DIR, 'images')
TEST_IMAGES_DIR = os.path.join(DATA_DIR, 'images')

TRAIN_CSV_PATH = os.path.join(DATA_DIR, 'train.csv')
TEST_CSV_PATH = os.path.join(DATA_DIR, 'test.csv')

MODEL_SAVE_PATH = os.path.join(MODELS_DIR, 'handwritten_name_ocr_model.pth')

# --- Character Set and OCR Configuration ---
CHARS = " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~"
BLANK_TOKEN_SYMBOL = 'Þ' 
VOCABULARY = CHARS + BLANK_TOKEN_SYMBOL
NUM_CLASSES = len(VOCABULARY)
BLANK_TOKEN = VOCABULARY.find(BLANK_TOKEN_SYMBOL)

# --- Sanity Checks ---
if BLANK_TOKEN == -1:
    raise ValueError(f"Error: BLANK_TOKEN_SYMBOL '{BLANK_TOKEN_SYMBOL}' not found in VOCABULARY. Check config.py definitions.")
if BLANK_TOKEN >= NUM_CLASSES:
     raise ValueError(f"Error: BLANK_TOKEN index ({BLANK_TOKEN}) must be less than NUM_CLASSES ({NUM_CLASSES}).")

print(f"Config Loaded: NUM_CLASSES={NUM_CLASSES}, BLANK_TOKEN_INDEX={BLANK_TOKEN}")
print(f"Vocabulary Length: {len(VOCABULARY)}")
print(f"Blank Symbol: '{BLANK_TOKEN_SYMBOL}' at index {BLANK_TOKEN}")


# --- Image Preprocessing Parameters ---
IMG_HEIGHT = 32 # Target height for all input images to the model
MAX_IMG_WIDTH = 1024 # Adjust this value based on your typical image widths and available RAM

# --- Training Parameters ---
BATCH_SIZE = 10

# NEW: Dataset Limits
TRAIN_SAMPLES_LIMIT = 1000 
TEST_SAMPLES_LIMIT = 1000 

NUM_EPOCHS = 5
LEARNING_RATE = 0.001