Buckets:
| #!/usr/bin/env python3 | |
| import sys | |
| import os | |
| import json | |
| import random | |
| from typing import List, Dict, Any | |
| def test_imports(): | |
| print("🔍 تست import های پایه...") | |
| try: | |
| import numpy as np | |
| print("✅ NumPy") | |
| except ImportError: | |
| print("❌ NumPy") | |
| try: | |
| import matplotlib.pyplot as plt | |
| print("✅ Matplotlib") | |
| except ImportError: | |
| print("❌ Matplotlib") | |
| try: | |
| import networkx as nx | |
| print("✅ NetworkX") | |
| except ImportError: | |
| print("❌ NetworkX") | |
| try: | |
| from PIL import Image | |
| print("✅ PIL") | |
| except ImportError: | |
| print("❌ PIL") | |
| try: | |
| import torch | |
| print("✅ PyTorch") | |
| return True | |
| except ImportError: | |
| print("❌ PyTorch") | |
| return False | |
| def test_file_structure(): | |
| print("\n📁 تست ساختار فایلها...") | |
| required_files = [ | |
| "main.py", | |
| "run.sh", | |
| "requirements.txt", | |
| "README.md", | |
| "src/__init__.py", | |
| "src/config/config.py", | |
| "src/config/default_config.yaml", | |
| "src/models/neural_module_networks.py", | |
| "src/models/scene_graph_models.py", | |
| "src/models/hybrid_vqa.py", | |
| "src/data/dataset.py", | |
| "src/evaluation/metrics.py", | |
| "src/visualization/visualizer.py", | |
| "src/demo/demo.py", | |
| "src/utils/base_classes.py", | |
| ] | |
| missing_files = [] | |
| for file_path in required_files: | |
| if os.path.exists(file_path): | |
| print(f"✅ {file_path}") | |
| else: | |
| print(f"❌ {file_path}") | |
| missing_files.append(file_path) | |
| return len(missing_files) == 0 | |
| def test_config(): | |
| print("\n⚙️ تست فایل تنظیمات...") | |
| try: | |
| import yaml | |
| with open("src/config/default_config.yaml", "r") as f: | |
| config = yaml.safe_load(f) | |
| required_sections = ["data", "model", "training", "evaluation", "logging"] | |
| for section in required_sections: | |
| if section in config: | |
| print(f"✅ بخش {section}") | |
| else: | |
| print(f"❌ بخش {section}") | |
| return False | |
| print("✅ فایل تنظیمات معتبر است") | |
| return True | |
| except Exception as e: | |
| print(f"❌ خطا در فایل تنظیمات: {e}") | |
| return False | |
| def test_synthetic_data(): | |
| print("\n📊 تست دادههای شبیهسازی شده...") | |
| questions = [ | |
| "What color is the car?", | |
| "How many people are there?", | |
| "Is there a dog in the image?", | |
| "What is the person doing?", | |
| "Where is the ball?", | |
| ] | |
| answers = ["red", "3", "yes", "walking", "on the ground"] | |
| print(f"✅ {len(questions)} سوال نمونه") | |
| print(f"✅ {len(answers)} پاسخ نمونه") | |
| question_types = [] | |
| for q in questions: | |
| if q.startswith("What color"): | |
| question_types.append("attribute") | |
| elif q.startswith("How many"): | |
| question_types.append("counting") | |
| elif q.startswith("Is there"): | |
| question_types.append("yes_no") | |
| elif q.startswith("What is"): | |
| question_types.append("activity") | |
| elif q.startswith("Where"): | |
| question_types.append("spatial") | |
| else: | |
| question_types.append("unknown") | |
| print(f"✅ {len(set(question_types))} نوع سوال شناسایی شد") | |
| return True | |
| def test_metrics(): | |
| print("\n📈 تست متریکهای ارزیابی...") | |
| predictions = ["red", "3", "yes", "walking", "on the ground"] | |
| ground_truths = ["red", "3", "yes", "walking", "on the ground"] | |
| correct = sum(1 for p, gt in zip(predictions, ground_truths) if p == gt) | |
| accuracy = correct / len(predictions) | |
| print(f"✅ دقت: {accuracy:.3f}") | |
| print(f"✅ {correct}/{len(predictions)} پاسخ صحیح") | |
| return True | |
| def test_visualization(): | |
| print("\n🎨 تست ابزارهای تجسم...") | |
| try: | |
| import matplotlib.pyplot as plt | |
| import numpy as np | |
| models = ["NMN", "Scene Graph", "Hybrid"] | |
| accuracies = [0.85, 0.78, 0.92] | |
| plt.figure(figsize=(8, 6)) | |
| plt.bar(models, accuracies, color=["skyblue", "lightgreen", "lightcoral"]) | |
| plt.title("مقایسه دقت مدلها") | |
| plt.ylabel("دقت") | |
| plt.ylim(0, 1) | |
| for i, acc in enumerate(accuracies): | |
| plt.text(i, acc + 0.01, f"{acc:.3f}", ha="center", va="bottom") | |
| plt.tight_layout() | |
| plt.savefig("test_visualization.png", dpi=150, bbox_inches="tight") | |
| plt.close() | |
| print("✅ نمودار تست ایجاد شد: test_visualization.png") | |
| return True | |
| except Exception as e: | |
| print(f"❌ خطا در تجسم: {e}") | |
| return False | |
| def test_scene_graph(): | |
| print("\n🕸️ تست گراف صحنه...") | |
| try: | |
| import networkx as nx | |
| G = nx.Graph() | |
| G.add_node(1, type="person", color="blue") | |
| G.add_node(2, type="car", color="red") | |
| G.add_node(3, type="dog", color="brown") | |
| G.add_edge(1, 3, relation="near") | |
| G.add_edge(2, 3, relation="next to") | |
| print(f"✅ {G.number_of_nodes()} گره (اشیاء)") | |
| print(f"✅ {G.number_of_edges()} یال (روابط)") | |
| person_nodes = [n for n, d in G.nodes(data=True) if d.get("type") == "person"] | |
| print(f"✅ {len(person_nodes)} شخص یافت شد") | |
| return True | |
| except Exception as e: | |
| print(f"❌ خطا در گراف صحنه: {e}") | |
| return False | |
| def run_all_tests(): | |
| print("🧪 تست کامل سیستم VQA") | |
| print("=" * 50) | |
| tests = [ | |
| ("Import ها", test_imports), | |
| ("ساختار فایلها", test_file_structure), | |
| ("تنظیمات", test_config), | |
| ("دادههای شبیهسازی", test_synthetic_data), | |
| ("متریکها", test_metrics), | |
| ("تجسم", test_visualization), | |
| ("گراف صحنه", test_scene_graph), | |
| ] | |
| results = [] | |
| for test_name, test_func in tests: | |
| try: | |
| result = test_func() | |
| results.append((test_name, result)) | |
| except Exception as e: | |
| print(f"❌ خطا در {test_name}: {e}") | |
| results.append((test_name, False)) | |
| print("\n📊 خلاصه نتایج:") | |
| print("=" * 30) | |
| passed = 0 | |
| for test_name, result in results: | |
| status = "✅ PASS" if result else "❌ FAIL" | |
| print(f"{status} {test_name}") | |
| if result: | |
| passed += 1 | |
| print(f"\n🎯 {passed}/{len(results)} تست موفق") | |
| if passed == len(results): | |
| print("🎉 همه تستها موفق!") | |
| return True | |
| else: | |
| print("⚠️ برخی تستها ناموفق") | |
| return False | |
| if __name__ == "__main__": | |
| success = run_all_tests() | |
| sys.exit(0 if success else 1) | |
Xet Storage Details
- Size:
- 7.05 kB
- Xet hash:
- b4720eaa3c4d80f72d79f153a454da7cabcc065700c405bd138614e90a506fdf
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.