pytti-tools / pytti-book

PyTTI Documentation and Tutorials
https://pytti-tools.github.io/pytti-book/intro.html
36 stars 10 forks source link

NameError: name 'Image' is not defined when prompting with a direct video mask #21

Closed nelsontseng0704 closed 2 years ago

nelsontseng0704 commented 2 years ago

Hi Pytti team,

when I tired out "scenes:sunlight:3_[production ID4508066.mp4]|midnight:3[-production ID_4508066.mp4]" on Google Colab, I encountered the erroe "NameError: name 'Image' is not defined". I tried to add hot fix code like "from PIL import Image" in rotoscoper.py but still not working.

Best,

2022-03-14 16:05:09.307 | DEBUG    | pytti.workhorse:_main:187 - {'scenes': 'sunlight:3_[production ID_4508066.mp4]|midnight:3_[-production ID_4508066.mp4]', 'scene_prefix': '', 'scene_suffix': '', 'interpolation_steps': 0, 'steps_per_scene': 500, 'direct_image_prompts': '', 'init_image': '', 'direct_init_weight': '', 'semantic_init_weight': '', 'image_model': 'Limited Palette', 'width': 720, 'height': 448, 'pixel_size': 1, 'smoothing_weight': 0.02, 'vqgan_model': 'sflckr', 'random_initial_palette': False, 'palette_size': 6, 'palettes': 9, 'gamma': 1, 'hdr_weight': 0.01, 'palette_normalization_weight': 0.2, 'show_palette': False, 'target_palette': '', 'lock_palette': False, 'animation_mode': '3D', 'sampling_mode': 'bicubic', 'infill_mode': 'wrap', 'pre_animation_steps': 100, 'steps_per_frame': 50, 'frames_per_second': 12, 'direct_stabilization_weight': '', 'semantic_stabilization_weight': '', 'depth_stabilization_weight': '', 'edge_stabilization_weight': '', 'flow_stabilization_weight': '', 'video_path': '', 'frame_stride': 1, 'reencode_each_frame': True, 'flow_long_term_samples': 1, 'translate_x': '-1700*sin(radians(1.5))', 'translate_y': '0', 'translate_z_3d': '(50+10*t)*sin(t/10*pi)**2', 'rotate_3d': '[cos(radians(1.5)), 0, -sin(radians(1.5))/sqrt(2), sin(radians(1.5))/sqrt(2)]', 'rotate_2d': '5', 'zoom_x_2d': '0', 'zoom_y_2d': '0', 'lock_camera': True, 'field_of_view': 60, 'near_plane': 1, 'far_plane': 10000, 'file_namespace': 'default', 'allow_overwrite': False, 'display_every': 50, 'clear_every': 0, 'display_scale': 1, 'save_every': 50, 'backups': 5, 'show_graphs': False, 'approximate_vram_usage': False, 'ViTB32': True, 'ViTB16': False, 'RN50': False, 'RN50x4': False, 'ViTL14': False, 'RN101': False, 'RN50x16': False, 'RN50x64': False, 'learning_rate': None, 'reset_lr_each_frame': True, 'seed': -19922333275351923, 'cutouts': 40, 'cut_pow': 2, 'cutout_border': 0.25, 'gradient_accumulation_steps': 1, 'border_mode': 'clamp', 'models_parent_dir': '.'}
2022-03-14 16:05:09.311 | DEBUG    | pytti.workhorse:_main:188 - {'scenes': 'sunlight:3_[production ID_4508066.mp4]|midnight:3_[-production ID_4508066.mp4]', 'scene_prefix': '', 'scene_suffix': '', 'interpolation_steps': 0, 'steps_per_scene': 500, 'direct_image_prompts': '', 'init_image': '', 'direct_init_weight': '', 'semantic_init_weight': '', 'image_model': 'Limited Palette', 'width': 720, 'height': 448, 'pixel_size': 1, 'smoothing_weight': 0.02, 'vqgan_model': 'sflckr', 'random_initial_palette': False, 'palette_size': 6, 'palettes': 9, 'gamma': 1, 'hdr_weight': 0.01, 'palette_normalization_weight': 0.2, 'show_palette': False, 'target_palette': '', 'lock_palette': False, 'animation_mode': '3D', 'sampling_mode': 'bicubic', 'infill_mode': 'wrap', 'pre_animation_steps': 100, 'steps_per_frame': 50, 'frames_per_second': 12, 'direct_stabilization_weight': '', 'semantic_stabilization_weight': '', 'depth_stabilization_weight': '', 'edge_stabilization_weight': '', 'flow_stabilization_weight': '', 'video_path': '', 'frame_stride': 1, 'reencode_each_frame': True, 'flow_long_term_samples': 1, 'translate_x': '-1700*sin(radians(1.5))', 'translate_y': '0', 'translate_z_3d': '(50+10*t)*sin(t/10*pi)**2', 'rotate_3d': '[cos(radians(1.5)), 0, -sin(radians(1.5))/sqrt(2), sin(radians(1.5))/sqrt(2)]', 'rotate_2d': '5', 'zoom_x_2d': '0', 'zoom_y_2d': '0', 'lock_camera': True, 'field_of_view': 60, 'near_plane': 1, 'far_plane': 10000, 'file_namespace': 'default', 'allow_overwrite': False, 'display_every': 50, 'clear_every': 0, 'display_scale': 1, 'save_every': 50, 'backups': 5, 'show_graphs': False, 'approximate_vram_usage': False, 'ViTB32': True, 'ViTB16': False, 'RN50': False, 'RN50x4': False, 'ViTL14': False, 'RN101': False, 'RN50x16': False, 'RN50x64': False, 'learning_rate': None, 'reset_lr_each_frame': True, 'seed': -19922333275351923, 'cutouts': 40, 'cut_pow': 2, 'cutout_border': 0.25, 'gradient_accumulation_steps': 1, 'border_mode': 'clamp', 'models_parent_dir': '.'}
2022-03-14 16:05:09.521 | DEBUG    | pytti.workhorse:do_run:242 - 40
2022-03-14 16:05:09.532 | INFO     | pytti.workhorse:parse_scenes:110 - Loading prompts...
2022-03-14 16:05:09.846 | INFO     | pytti.rotoscoper:get_frames:41 - loaded 751 frames. for production ID_4508066.mp4
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
[<ipython-input-19-3894f198f437>](https://localhost:8080/#) in <module>()
      6 
      7 # function wraps step 2.3 of the original p5 notebook
----> 8 render_frames(cfg)

8 frames
[/usr/local/lib/python3.7/dist-packages/hydra/main.py](https://localhost:8080/#) in decorated_main(cfg_passthrough)
     41         def decorated_main(cfg_passthrough: Optional[DictConfig] = None) -> Any:
     42             if cfg_passthrough is not None:
---> 43                 return task_function(cfg_passthrough)
     44             else:
     45                 args = get_args_parser()

[/usr/local/lib/python3.7/dist-packages/pytti/workhorse.py](https://localhost:8080/#) in _main(cfg)
    586                 torch.cuda.empty_cache()
    587         else:
--> 588             do_run()
    589             logger.info("Complete.")
    590             gc.collect()

[/usr/local/lib/python3.7/dist-packages/pytti/workhorse.py](https://localhost:8080/#) in do_run()
    257                 scenes=params.scenes,
    258                 scene_prefix=params.scene_prefix,
--> 259                 scene_suffix=params.scene_suffix,
    260             )
    261 

[/usr/local/lib/python3.7/dist-packages/pytti/workhorse.py](https://localhost:8080/#) in parse_scenes(embedder, scenes, scene_prefix, scene_suffix)
    115             if p.strip()
    116         ]
--> 117         for stage in scenes.split("||")
    118         if stage
    119     ]

[/usr/local/lib/python3.7/dist-packages/pytti/workhorse.py](https://localhost:8080/#) in <listcomp>(.0)
    116         ]
    117         for stage in scenes.split("||")
--> 118         if stage
    119     ]
    120     logger.info("Prompts loaded.")

[/usr/local/lib/python3.7/dist-packages/pytti/workhorse.py](https://localhost:8080/#) in <listcomp>(.0)
    113             parse_prompt(embedder, p.strip())
    114             for p in (scene_prefix + stage + scene_suffix).strip().split("|")
--> 115             if p.strip()
    116         ]
    117         for stage in scenes.split("||")

[/usr/local/lib/python3.7/dist-packages/torch/autograd/grad_mode.py](https://localhost:8080/#) in decorate_context(*args, **kwargs)
     26         def decorate_context(*args, **kwargs):
     27             with self.__class__():
---> 28                 return func(*args, **kwargs)
     29         return cast(F, decorate_context)
     30 

[/usr/local/lib/python3.7/dist-packages/pytti/Perceptor/Prompt.py](https://localhost:8080/#) in parse_prompt(embedder, prompt_string, pil_image, device)
    223     if roto is not None:
    224         roto.target = out
--> 225         roto.update(0)
    226     return out
    227 

[/usr/local/lib/python3.7/dist-packages/pytti/rotoscoper.py](https://localhost:8080/#) in update(self, frame_n)
     66         """
     67         if self.target is None:
---> 68             return
     69         mask_pil = Image.fromarray(self.frames.get_data(frame_n)).convert("L")
     70         self.target.set_mask(mask_pil, self.inverted)

NameError: name 'Image' is not defined
dmarx commented 2 years ago

This should be fixed in the latest version. Can you try updating your pytti version following these instructions and let me know if you still experience issues? https://pytti-tools.github.io/pytti-book/Setup.html#uninstalling-and-or-updating