Upload folder using huggingface_hub
Browse files
README.md
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Matrix Game Image to Action
|
| 2 |
+
|
| 3 |
+
Custom block that generates action inputs for [Matrix Game](https://huggingface.co/Skywork/Matrix-Game-2.0) interactive world model.
|
| 4 |
+
|
| 5 |
+
# How to use
|
| 6 |
+
|
| 7 |
+
```python
|
| 8 |
+
import torch
|
| 9 |
+
from diffusers import ModularPipelineBlocks
|
| 10 |
+
from diffusers.utils import export_to_video, load_image
|
| 11 |
+
from diffusers.modular_pipelines import WanModularPipeline
|
| 12 |
+
|
| 13 |
+
class MatrixGameWanModularPipeline(WanModularPipeline):
|
| 14 |
+
"""
|
| 15 |
+
A ModularPipeline for MatrixGameWan.
|
| 16 |
+
|
| 17 |
+
<Tip warning={true}>
|
| 18 |
+
|
| 19 |
+
This is an experimental feature and is likely to change in the future.
|
| 20 |
+
|
| 21 |
+
</Tip>
|
| 22 |
+
"""
|
| 23 |
+
|
| 24 |
+
@property
|
| 25 |
+
def default_sample_height(self):
|
| 26 |
+
return 44
|
| 27 |
+
|
| 28 |
+
@property
|
| 29 |
+
def default_sample_width(self):
|
| 30 |
+
return 80
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
blocks = ModularPipelineBlocks.from_pretrained("diffusers/matrix-game-2-modular", trust_remote_code=True)
|
| 34 |
+
image_to_action_block = ModularPipelineBlocks.from_pretrained("dn6/matrix-game-image-to-action", trust_remote_code=True)
|
| 35 |
+
|
| 36 |
+
blocks.sub_blocks.insert("image_to_action", image_to_action_block, 0)
|
| 37 |
+
|
| 38 |
+
pipe = MatrixGameWanModularPipeline(blocks, "diffusers-internal-dev/matrix-game-2-modular")
|
| 39 |
+
pipe.load_components(trust_remote_code=True, device_map="cuda", torch_dtype={"default": torch.bfloat16, "vae": torch.float32})
|
| 40 |
+
|
| 41 |
+
image = load_image("https://images.unsplash.com/photo-1730652201845-095193ddb555?q=80&w=1322&auto=format&fit=crop&ixlib=rb-4.1.0&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D")
|
| 42 |
+
prompt = "Turn around and look at what's behind you"
|
| 43 |
+
|
| 44 |
+
output = pipe(image=image, num_frames=141, prompt=prompt, num_inference_steps=8)
|
| 45 |
+
export_to_video(output.values['videos'][0], "matrix-game-vlm.mp4")
|
| 46 |
+
```
|
block.py
CHANGED
|
@@ -145,3 +145,4 @@ class ImageToMatrixGameAction(ModularPipelineBlocks):
|
|
| 145 |
except Exception as e:
|
| 146 |
logger.warning("Unable to generate actions. Defaulting to random actions")
|
| 147 |
return components, state
|
|
|
|
|
|
| 145 |
except Exception as e:
|
| 146 |
logger.warning("Unable to generate actions. Defaulting to random actions")
|
| 147 |
return components, state
|
| 148 |
+
|