Views
No views yet
pip install torch torchvision pillow numpy1import torch
2from PIL import Image
3import torchvision.transforms as transforms
4from split_model import SplitModel
5
6# Load model
7device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
8model = SplitModel().to(device)
9
10# Load checkpoint
11checkpoint = torch.load('split_model.pth', map_location=device)
12model.load_state_dict(checkpoint['model_state_dict'])
13model.eval()
14
15# Prepare image
16transform = transforms.Compose([
17 transforms.Resize((960, 960)),
18 transforms.ToTensor(),
19 transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225])
20])
21
22image = Image.open('table_image.png').convert('RGB')
23image_tensor = transform(image).unsqueeze(0).to(device)
24
25# Predict
26with torch.no_grad():
27 h_pred, v_pred = model(image_tensor) # Returns [1, 480] predictions
28
29 # Upsample to 960 for visualization
30 h_pred = h_pred.repeat_interleave(2, dim=1) # [1, 960]
31 v_pred = v_pred.repeat_interleave(2, dim=1) # [1, 960]
32
33 # Apply threshold
34 h_splits = (h_pred > 0.5).float()
35 v_splits = (v_pred > 0.5).float()
36
37 # Count rows and columns
38 num_rows = h_splits.sum().item() + 1
39 num_cols = v_splits.sum().item() + 1
40
41 print(f"Detected {num_rows} rows and {num_cols} columns")1python test_split_by_images_folder.py \
2 --image-folder /path/to/images \
3 --output-folder predictions_output \
4 --model-path split_model.pth \
5 --threshold 0.5split_model.py - Model architecture and dataset classestrain_split_fixed.py - Training scripttest_split_by_images_folder.py - Inference and visualization scriptsplit_model.pth - Trained model weights1@article{tablet2025,
2 title={TABLET: Learning From Instructions For Tabular Data},
3 author={[Authors from paper]},
4 journal={arXiv preprint arXiv:2506.07015},
5 year={2025}
6}