|
|
|
|
|
""" |
|
|
Quick test to verify the tensor creation fix works. |
|
|
This creates a simple test scenario to check if our fix resolves the padding issue. |
|
|
""" |
|
|
|
|
|
import sys |
|
|
import tempfile |
|
|
from pathlib import Path |
|
|
import numpy as np |
|
|
from PIL import Image |
|
|
|
|
|
def create_simple_test_frames(num_frames=8): |
|
|
"""Create simple test frames.""" |
|
|
frames = [] |
|
|
for i in range(num_frames): |
|
|
|
|
|
img_array = np.full((224, 224, 3), fill_value=(i * 30) % 255, dtype=np.uint8) |
|
|
frame = Image.fromarray(img_array, 'RGB') |
|
|
frames.append(frame) |
|
|
return frames |
|
|
|
|
|
def test_tensor_creation(): |
|
|
"""Test the tensor creation with our fix.""" |
|
|
print("π§ͺ Testing Tensor Creation Fix") |
|
|
print("=" * 40) |
|
|
|
|
|
try: |
|
|
|
|
|
from transformers import AutoImageProcessor |
|
|
import torch |
|
|
print("β
Imports successful") |
|
|
|
|
|
|
|
|
processor = AutoImageProcessor.from_pretrained("facebook/timesformer-base-finetuned-k400") |
|
|
print("β
Processor loaded") |
|
|
|
|
|
|
|
|
frames = create_simple_test_frames(8) |
|
|
print(f"β
Created {len(frames)} test frames") |
|
|
|
|
|
|
|
|
try: |
|
|
inputs = processor(images=frames, return_tensors="pt", padding=True) |
|
|
print(f"β
Tensor created successfully!") |
|
|
print(f" Shape: {inputs['pixel_values'].shape}") |
|
|
print(f" Dtype: {inputs['pixel_values'].dtype}") |
|
|
return True |
|
|
|
|
|
except Exception as e: |
|
|
print(f"β Primary approach failed: {e}") |
|
|
|
|
|
|
|
|
try: |
|
|
inputs = processor(images=[frames], return_tensors="pt", padding=True) |
|
|
print(f"β
Fallback approach worked!") |
|
|
print(f" Shape: {inputs['pixel_values'].shape}") |
|
|
return True |
|
|
except Exception as e2: |
|
|
print(f"β Fallback also failed: {e2}") |
|
|
return False |
|
|
|
|
|
except Exception as e: |
|
|
print(f"β Test setup failed: {e}") |
|
|
return False |
|
|
|
|
|
def test_prediction_pipeline(): |
|
|
"""Test the full prediction pipeline.""" |
|
|
print("\n㪠Testing Full Pipeline") |
|
|
print("=" * 40) |
|
|
|
|
|
try: |
|
|
from predict import predict_actions |
|
|
print("β
Import successful") |
|
|
|
|
|
|
|
|
with tempfile.TemporaryDirectory() as tmp_dir: |
|
|
tmp_path = Path(tmp_dir) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
print("β οΈ Note: Full video test requires a real video file") |
|
|
print(" The tensor fix is now in place in predict.py") |
|
|
|
|
|
return True |
|
|
|
|
|
except Exception as e: |
|
|
print(f"β Pipeline test failed: {e}") |
|
|
return False |
|
|
|
|
|
if __name__ == "__main__": |
|
|
print("π§ Quick Test Suite for Tensor Fix") |
|
|
print("=" * 50) |
|
|
|
|
|
|
|
|
test1_passed = test_tensor_creation() |
|
|
|
|
|
|
|
|
test2_passed = test_prediction_pipeline() |
|
|
|
|
|
print("\nπ Results:") |
|
|
print(f" Tensor creation: {'β
PASSED' if test1_passed else 'β FAILED'}") |
|
|
print(f" Pipeline check: {'β
PASSED' if test2_passed else 'β FAILED'}") |
|
|
|
|
|
if test1_passed: |
|
|
print("\nπ The tensor creation fix appears to be working!") |
|
|
print(" You can now try uploading a video to the Streamlit app.") |
|
|
else: |
|
|
print("\nπ₯ The fix may need more work. Check the error messages above.") |
|
|
|
|
|
print("\nπ‘ Next step: Run 'streamlit run app.py' and test with a real video") |
|
|
|