This project provides a fully automated pipeline that automatically scrapes images from the cosmos.so CDN and trains an image classification model.
- Automated Web Scraping: Automatic collection of image URLs from cosmos.so CDN
- Intelligent Category Classification: Automatic labeling based on URL paths
- Image Download and Preprocessing: 224x224 resize, RGB normalization
- CNN Model Training: PyTorch-based image classification model
- Full Automation: One-click execution from scraping to model training
- x_train:
https://cdn.cosmos.so/book/layout/book1.webp(scraped image URL) - category:
"book_layout"(category automatically extracted from URL path) - y_train:
"book_layout"(automatically generated label)
book_layout: Book layoutphotography: Photographydesign: Designartwork: Artworkminimal_design: Minimal designabstract_art: Abstract arttexture: Texturepattern: Patternlayout: Layoutcreative: Creativeblack_white: Black and whitemonochrome: Monochromecolorful: Colorfulvintage: Vintagemodern: Modernclassic: Classic
Vision2026Trainer/
├── scrapers/ # Image scraping modules
│ ├── cosmos_scraper.py
│ ├── cosmos_real_scraper.py
│ └── improved_scraper.py
├── pipelines/ # Training and processing pipelines
│ ├── auto_scraping_pipeline.py
│ ├── word_based_pipeline.py
│ ├── high_quality_pipeline.py
│ └── image_classification_pipeline.py
├── gui/ # User interface applications
│ ├── cosmos_gui_v4_gemini.py # Current GUI with Gemini API
│ ├── cosmos_gui_pyqt6.py
│ ├── cosmos_gui_v2.py
│ ├── cosmos_gui.py
│ ├── simple_gui.py
│ ├── ultra_simple_gui.py
│ └── web_gui.py
├── tests/ # Test scripts
│ ├── test_auto_scraping.py
│ ├── test_pipeline.py
│ └── test_image_preview.py
├── utils/ # Utility functions and helpers
│ ├── cosmos_real_final.py
│ └── enhance_categories.py
├── config/ # Configuration files
│ ├── config.yml
│ └── env_example.txt
├── docs/ # Documentation
│ ├── CLAUDE_AI_AUTOMATION_GUIDE.md
│ ├── CLAUDE_REAL_API_GUIDE.md
│ └── CLOUDFLARE_ERROR_525_SOLUTION.md
├── dataset/ # Training data and CSV files
│ ├── x_train.csv
│ ├── y_train.csv
│ └── words*.csv
├── models/ # Trained PyTorch models
│ └── *.pt
├── results/ # Training results and metrics
│ └── *.png
├── mcp_archive/ # MCP (Model Context Protocol) archive
├── templates/ # Web templates and assets
├── requirements.txt # Required packages list
└── README.md # This file
# Python 3.10 or higher required
python3 --version
# Create virtual environment (optional)
python3 -m venv venv
source venv/bin/activate # macOS/Linux
# or
venv\Scripts\activate # Windows
# Install required packages
pip install -r requirements.txt# Run fully automated pipeline
python3 pipelines/auto_scraping_pipeline.py
# Or run word-based pipeline
python3 pipelines/word_based_pipeline.py# Test automated scraping pipeline
python3 tests/test_auto_scraping.py
# Test original manual pipeline
python3 tests/test_pipeline.py# Run main GUI with Gemini API
python3 gui/cosmos_gui_v4_gemini.py
# Run PyQt6 GUI
python3 gui/cosmos_gui_pyqt6.py
# Run simple GUI
python3 gui/simple_gui.pyThe pipeline automatically executes in the following steps:
- Web Scraping: Automatic collection of image URLs from cosmos.so CDN
- Category Classification: Automatic labeling based on URL paths
- CSV Generation: Generate x_train.csv, y_train.csv files
- Data Preprocessing: Image download, resize, normalization
- Model Training: CNN model training (10 epochs)
- Result Saving: Save model file and visualization graph
# In the main() function of auto_scraping_pipeline.py
pipeline = AutoScrapingPipeline()
# Adjust number of pages to scrape
image_urls, labels = pipeline.scrape_and_categorize(max_pages=10) # Default: 5# In the CosmosScraper class of auto_scraping_pipeline.py
category_keywords = {
'book': 'book_layout',
'art': 'artwork',
'photo': 'photography',
# Add new keywords
'nature': 'nature_photography',
'urban': 'urban_design',
# ...
}# In the CosmosScraper class of auto_scraping_pipeline.py
def __init__(self, base_url: str = "https://your-custom-cdn.com", timeout: int = 10):
self.base_url = base_url
# ...If you have actual image files locally, you can use the base_url parameter of CosmosImageDataset:
dataset = CosmosImageDataset(
image_urls,
labels,
transform=transform,
base_url="/path/to/your/images" # Local image directory
).webp,.png,.jpg,.jpeg,.gif,.bmp,.tiff
- HTML Parsing: Structured data extraction using BeautifulSoup
- Link Following: Navigate through page links to find images
- Duplicate Removal: Automatic removal of identical image URLs
- Error Handling: Robust handling of network errors and parsing errors
- URL Path Analysis: Extract keywords from
/book/layout/,/photo/minimal/etc. - Filename Analysis: Extract categories from
book_spread_001.webpetc. - Keyword Matching: Match with predefined keyword dictionary
- Default Category: Assign 'general' category if no match is found
CNN model structure used:
Conv2D(3→32) → ReLU → MaxPool2D
Conv2D(32→64) → ReLU → MaxPool2D
Conv2D(64→128) → ReLU → MaxPool2D
Flatten → Dense(128×28×28→512) → ReLU → Dropout(0.5)
Dense(512→num_classes) → Softmax
After execution completion, the following files are generated:
./dataset/x_train.csv: Scraped image URLs and automatically generated categories./dataset/y_train.csv: Automatically generated label information./models/model.pt: Trained PyTorch model./results/metrics.png: Training loss and accuracy graph
- Python 3.10 or higher
- PyTorch 2.0.0 or higher
- BeautifulSoup4 4.11.0 or higher
- Internet connection (for scraping and image download)
- Sufficient disk space (for image caching)
-
Scraping Failure:
- Check network connection
- Check target site's robots.txt
- Update User-Agent header
-
Image Download Failure:
- Validate URL
- Adjust timeout settings
-
Memory Insufficient:
- Reduce batch size
- Adjust image resolution
-
Inaccurate Category Classification:
- Update keyword dictionary
- Analyze URL patterns
Detailed logs are output during program execution, so check logs when problems occur.
- Adjust scraping scope with
max_pagesparameter - Adjust network timeout with
timeoutparameter - Adjust memory usage with
batch_sizeparameter
This project is licensed under the Apache License 2.0. See the LICENSE file for details.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
The mcp_archive/ folder contains previously used MCP (Model Context Protocol) related files. These have been archived as the project now uses direct Gemini API integration for better performance and reliability.
- Active:
cosmos_gui_v4_gemini.py- Direct Gemini API integration - Archived: All MCP-related files in
mcp_archive/folder
If you need to restore MCP functionality, see mcp_archive/README.md for detailed instructions.
- Comply with the terms of service of target sites when web scraping
- Be careful not to overload servers with excessive requests
- Be cautious when using copyrighted images