File size: 7,914 Bytes
4a2571f
 
c5c8ea2
4a2571f
 
c5c8ea2
4a2571f
c5c8ea2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4a2571f
 
c5c8ea2
 
 
 
 
 
 
 
 
4a2571f
 
c5c8ea2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4a2571f
 
 
 
c5c8ea2
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
---
base_model: openai/clip-vit-base-patch32
license: mit
---

# CAT-CLIP: Cryptocurrency Analysis Tool - CLIP

A simplified ONNX implementation of OpenAI's CLIP model specifically optimized for cryptocurrency-related image analysis tasks. This repository provides quantized ONNX models based on [Xenova/clip-vit-base-patch32](https://huggingface.co/Xenova/clip-vit-base-patch32), which itself is derived from [openai/clip-vit-base-patch32](https://huggingface.co/openai/clip-vit-base-patch32).

## Overview

This repository contains:
- **Quantized ONNX models** (`text_model_q4f16.onnx`, `vision_model_q4f16.onnx`) for efficient inference
- **Tokenizer and preprocessing configurations** compatible with Transformers.js
- **Optimized model weights** for cryptocurrency-specific image classification tasks

While currently a repackaged version of the base model, this repository serves as a foundation for future cryptocurrency-specific model distillation and fine-tuning efforts.

## Usage

### Python (ONNX Runtime)

For more advanced cryptocurrency-specific use cases, see the example implementation in our classifier:

```python
from src.models.classifier import ImageClassifier
from src.config.config import Config
from PIL import Image

# Initialize classifier with crypto-specific classes
config = Config()
classifier = ImageClassifier(config)

# Load image
image = Image.open("path/to/crypto_image.jpg")

# Classify for cryptocurrency content
result = classifier.predict(image)
print(result)
# Output: {'seed_phrase': 0.95, 'address': 0.02, 'handwriting': 0.03}

# Get final classification
classification = classifier._classify_image(image, result)
print(f"Classification: {classification}")
# Output: Classification: seed_phrase
```

**Batch processing:**
```python
images = [Image.open(f"image_{i}.jpg") for i in range(5)]
results, classifications = classifier.predict_batch(images)

for i, (result, classification) in enumerate(zip(results, classifications)):
    print(f"Image {i}: {classification} (confidence: {result[classification]:.3f})")
```

## Current Capabilities

The model is currently optimized for three main cryptocurrency-related classification tasks:

1. **Seed Phrase Detection**: Identifies images containing cryptocurrency recovery/seed phrases or mnemonics
2. **Crypto Address Detection**: Recognizes cryptocurrency addresses (26-35 characters) and associated QR codes
3. **Handwriting Detection**: Detects handwritten text, particularly useful for identifying handwritten wallet information

## Future Work

We have several exciting developments planned to enhance this model's efficacy for cryptocurrency-specific problemsets:

### Model Distillation & Optimization
- **Domain-specific distillation**: Create a smaller, faster model trained specifically on cryptocurrency-related imagery
- **Quantization improvements**: Explore INT8 and mixed-precision quantization for even better performance
- **Hardware-specific optimizations**: Optimize models for mobile devices and edge computing scenarios

### Enhanced Crypto-Specific Features
- **Multi-language support**: Extend seed phrase detection to support mnemonics in multiple languages
- **Blockchain-specific addressing**: Improve detection for various blockchain address formats (Bitcoin, Ethereum, etc.)
- **Document structure analysis**: Better understanding of wallet documents, exchange screenshots, and transaction receipts
- **Temporal analysis**: Detect and analyze sequences of images for comprehensive wallet recovery scenarios

### Training Data & Fine-tuning
- **Synthetic data generation**: Create large-scale synthetic datasets of cryptocurrency-related imagery
- **Active learning pipeline**: Implement continuous learning from user feedback and corrections
- **Cross-modal training**: Incorporate OCR text extraction with visual understanding for better accuracy

### Performance & Scalability
- **Real-time inference**: Optimize for sub-100ms inference times on consumer hardware
- **Batch processing optimizations**: Improve efficiency for large-scale image analysis tasks
- **Model compression**: Achieve similar accuracy with significantly smaller model sizes

### Integration & Deployment
- **REST API development**: Create production-ready APIs for easy integration
- **Browser extension support**: Enable direct use in web browsers for real-time analysis
- **Mobile SDKs**: Develop native mobile libraries for iOS and Android applications

## Model Architecture

- **Base Model**: OpenAI CLIP ViT-B/32
- **Vision Encoder**: Vision Transformer (ViT) with 32x32 patch size
- **Text Encoder**: Transformer-based text encoder
- **Quantization**: Q4F16 (4-bit weights, 16-bit activations)
- **Context Length**: 77 tokens
- **Image Resolution**: 224x224 pixels

## License

This project is licensed under the MIT License, consistent with the original OpenAI CLIP model.

### Original Model Licenses
- **OpenAI CLIP**: MIT License - [openai/CLIP](https://github.com/openai/CLIP)
- **Xenova CLIP**: MIT License - [Xenova/clip-vit-base-patch32](https://huggingface.co/Xenova/clip-vit-base-patch32)

The MIT License permits commercial use, modification, distribution, and private use. See the [LICENSE](https://github.com/openai/CLIP/blob/main/LICENSE) file in the original OpenAI repository for full details.

## Attribution

This work builds upon several excellent open-source projects:

- **OpenAI CLIP**: The foundational model and research by Alec Radford, Jong Wook Kim, et al.
- **Xenova (Joshua)**: ONNX conversion and Transformers.js compatibility
- **Hugging Face**: Model hosting and transformers library infrastructure
- **Microsoft ONNX Runtime**: High-performance inference engine

## Contributing

We welcome contributions to improve this cryptocurrency-specific CLIP implementation! Here's how you can help:

### Ways to Contribute

1. **Bug Reports**: Found an issue? Please open a GitHub issue with detailed reproduction steps
2. **Feature Requests**: Have ideas for crypto-specific enhancements? We'd love to hear them
3. **Code Contributions**: Submit pull requests for bug fixes or new features
4. **Dataset Contributions**: Help us build better training data for cryptocurrency use cases
5. **Documentation**: Improve our documentation, examples, and tutorials

### Development Setup

```bash
# Clone the repository
git clone https://github.com/yourusername/CAT-CLIP.git
cd CAT-CLIP

# Install dependencies
pip install -r requirements.txt

# Run tests
python -m pytest tests/
```

### Contribution Guidelines

- Follow PEP 8 style guidelines for Python code
- Include tests for new functionality
- Update documentation for any new features
- Ensure compatibility with both CPU and GPU inference
- Test changes across different image types and sizes

### Code of Conduct

This project follows the [Contributor Covenant](https://www.contributor-covenant.org/) Code of Conduct. Please be respectful and inclusive in all interactions.

## Citation

If you use this model in your research or applications, please cite:

```bibtex
@misc{cat-clip-2024,
  title={CAT-CLIP: Cryptocurrency Analysis Tool - CLIP},
  author={Your Name},
  year={2024},
  url={https://github.com/yourusername/CAT-CLIP}
}

@article{radford2021learning,
  title={Learning transferable visual models from natural language supervision},
  author={Radford, Alec and Kim, Jong Wook and Hallacy, Chris and Ramesh, Aditya and Goh, Gabriel and Agarwal, Sandhini and Sastry, Girish and Askell, Amanda and Mishkin, Pamela and Clark, Jack and others},
  journal={International conference on machine learning},
  year={2021}
}
```

---

**Note**: This is a specialized implementation intended for cryptocurrency-related image analysis. For general-purpose CLIP usage, consider using the original [OpenAI CLIP](https://github.com/openai/CLIP) or [Xenova's implementation](https://huggingface.co/Xenova/clip-vit-base-patch32) directly.