|
|
"""
|
|
|
Main script for running multi-modal inference using Helium framework.
|
|
|
Example usage for end users.
|
|
|
"""
|
|
|
import os
|
|
|
from inference_runner import InferenceRunner
|
|
|
|
|
|
def run_inference_example():
|
|
|
"""Example showing how to use the inference runner"""
|
|
|
|
|
|
|
|
|
MODEL_PATH = os.path.join(os.path.dirname(__file__), "checkpoints/model")
|
|
|
|
|
|
|
|
|
print("Initializing inference runner...")
|
|
|
runner = InferenceRunner(
|
|
|
model_path=MODEL_PATH,
|
|
|
device_id="vgpu0",
|
|
|
batch_size=4,
|
|
|
cache_dir="cache"
|
|
|
)
|
|
|
|
|
|
try:
|
|
|
|
|
|
print("\nRunning text-only inference...")
|
|
|
result = runner(text="Analyze this sentence.")
|
|
|
print("Text features shape:", result["text_features"].shape)
|
|
|
|
|
|
|
|
|
print("\nRunning multi-modal inference...")
|
|
|
result = runner(
|
|
|
text="Describe this image and sound:",
|
|
|
image_path="samples/scene.jpg",
|
|
|
audio_path="samples/audio.wav"
|
|
|
)
|
|
|
print("Available features:", list(result.keys()))
|
|
|
|
|
|
|
|
|
print("\nProcessing batch...")
|
|
|
texts = [f"Sample text {i}" for i in range(3)]
|
|
|
images = ["samples/img1.jpg", "samples/img2.jpg", "samples/img3.jpg"]
|
|
|
|
|
|
for text, img in zip(texts, images):
|
|
|
runner.add_to_batch(text=text, image_path=img)
|
|
|
|
|
|
batch_result = runner.process_batch()
|
|
|
print("Batch processing complete. Output shapes:")
|
|
|
for key, value in batch_result.items():
|
|
|
print(f" {key}: {value.shape}")
|
|
|
|
|
|
|
|
|
print("\nGenerating text from multi-modal context...")
|
|
|
generated = runner.generate_from_context(
|
|
|
context_text="What's happening in this scene?",
|
|
|
context_image="samples/scene.jpg",
|
|
|
context_audio="samples/ambient.wav",
|
|
|
max_length=50
|
|
|
)
|
|
|
print("Generated sequence shape:", generated.shape)
|
|
|
|
|
|
finally:
|
|
|
|
|
|
print("\nCleaning up resources...")
|
|
|
runner.cleanup()
|
|
|
|
|
|
def main():
|
|
|
"""Main entry point"""
|
|
|
try:
|
|
|
run_inference_example()
|
|
|
print("\nInference completed successfully!")
|
|
|
|
|
|
except FileNotFoundError as e:
|
|
|
print(f"\nError: Required file not found: {e}")
|
|
|
print("Please make sure all model files and samples are in the correct location.")
|
|
|
|
|
|
except ValueError as e:
|
|
|
print(f"\nError: Invalid input: {e}")
|
|
|
print("Please check your input values and formats.")
|
|
|
|
|
|
except Exception as e:
|
|
|
print(f"\nUnexpected error: {e}")
|
|
|
print("If this persists, please check the logs or contact support.")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
main()
|
|
|
|