From 7bed123ec51b13be145a3454aafc3edaa759d6eb Mon Sep 17 00:00:00 2001 From: Adam Letts Date: Tue, 5 Apr 2022 16:55:06 -0400 Subject: [PATCH] Fix Video Input mode's ffmpeg subprocess call, and improve imports --- Disco_Diffusion.ipynb | 27 ++++++++++++--------------- disco.py | 23 ++++++++++------------- 2 files changed, 22 insertions(+), 28 deletions(-) diff --git a/Disco_Diffusion.ipynb b/Disco_Diffusion.ipynb index fecc12a..d6e9673 100644 --- a/Disco_Diffusion.ipynb +++ b/Disco_Diffusion.ipynb @@ -478,52 +478,49 @@ "try:\n", " from CLIP import clip\n", "except:\n", - " if os.path.exists(\"CLIP\") is not True:\n", + " if not os.path.exists(\"CLIP\"):\n", " gitclone(\"https://github.com/openai/CLIP\")\n", " sys.path.append(f'{PROJECT_DIR}/CLIP')\n", "\n", "try:\n", " from guided_diffusion.script_util import create_model_and_diffusion\n", "except:\n", - " if os.path.exists(\"guided-diffusion\") is not True:\n", + " if not os.path.exists(\"guided-diffusion\"):\n", " gitclone(\"https://github.com/crowsonkb/guided-diffusion\")\n", " sys.path.append(f'{PROJECT_DIR}/guided-diffusion')\n", "\n", "try:\n", " from resize_right import resize\n", "except:\n", - " if os.path.exists(\"resize_right\") is not True:\n", + " if not os.path.exists(\"ResizeRight\"):\n", " gitclone(\"https://github.com/assafshocher/ResizeRight.git\")\n", " sys.path.append(f'{PROJECT_DIR}/ResizeRight')\n", "\n", "try:\n", " import py3d_tools\n", "except:\n", - " if os.path.exists('pytorch3d-lite') is not True:\n", + " if not os.path.exists('pytorch3d-lite'):\n", " gitclone(\"https://github.com/MSFTserver/pytorch3d-lite.git\")\n", " sys.path.append(f'{PROJECT_DIR}/pytorch3d-lite')\n", "\n", "try:\n", " from midas.dpt_depth import DPTDepthModel\n", "except:\n", - " if os.path.exists('MiDaS') is not True:\n", + " if not os.path.exists('MiDaS'):\n", " gitclone(\"https://github.com/isl-org/MiDaS.git\")\n", - " if os.path.exists('MiDaS/midas_utils.py') is not True:\n", + " if not os.path.exists('MiDaS/midas_utils.py'):\n", " shutil.move('MiDaS/utils.py', 'MiDaS/midas_utils.py')\n", " if not os.path.exists(f'{model_path}/dpt_large-midas-2f21e586.pt'):\n", " wget(\"https://github.com/intel-isl/DPT/releases/download/1_0/dpt_large-midas-2f21e586.pt\", model_path)\n", " sys.path.append(f'{PROJECT_DIR}/MiDaS')\n", "\n", "try:\n", - " sys.path.append(PROJECT_DIR)\n", + " sys.path.append(f'{PROJECT_DIR}/disco-diffusion')\n", " import disco_xform_utils as dxf\n", "except:\n", - " if os.path.exists(\"disco-diffusion\") is not True:\n", + " if not os.path.exists(\"disco-diffusion\"):\n", " gitclone(\"https://github.com/alembics/disco-diffusion.git\")\n", - " # Rename a file to avoid a name conflict..\n", - " if os.path.exists('disco_xform_utils.py') is not True:\n", - " shutil.move('disco-diffusion/disco_xform_utils.py', 'disco_xform_utils.py')\n", - " sys.path.append(PROJECT_DIR)\n", + " sys.path.append(f'{PROJECT_DIR}/disco-diffusion')\n", "\n", "import torch\n", "from dataclasses import dataclass\n", @@ -1672,7 +1669,7 @@ " alphas, sigmas = map(partial(append_dims, n=v.ndim), t_to_alpha_sigma(t))\n", " pred = input * alphas - v * sigmas\n", " eps = input * sigmas + v * alphas\n", - " return DiffusionOutput(v, pred, eps)" + " return DiffusionOutput(v, pred, eps)\n" ], "outputs": [], "execution_count": null @@ -1895,7 +1892,7 @@ "\n", "#Make folder for batch\n", "batchFolder = f'{outDirPath}/{batch_name}'\n", - "createPath(batchFolder)" + "createPath(batchFolder)\n" ], "outputs": [], "execution_count": null @@ -1942,7 +1939,7 @@ " f.unlink()\n", " except:\n", " print('')\n", - " vf = f'\"select=not(mod(n\\,{extract_nth_frame}))\"'\n", + " vf = f'select=not(mod(n\\,{extract_nth_frame}))'\n", " subprocess.run(['ffmpeg', '-i', f'{video_init_path}', '-vf', f'{vf}', '-vsync', 'vfr', '-q:v', '2', '-loglevel', 'error', '-stats', f'{videoFramesFolder}/%04d.jpg'], stdout=subprocess.PIPE).stdout.decode('utf-8')\n", " #!ffmpeg -i {video_init_path} -vf {vf} -vsync vfr -q:v 2 -loglevel error -stats {videoFramesFolder}/%04d.jpg\n", "\n", diff --git a/disco.py b/disco.py index d34383c..7087b75 100644 --- a/disco.py +++ b/disco.py @@ -450,52 +450,49 @@ if is_colab: try: from CLIP import clip except: - if os.path.exists("CLIP") is not True: + if not os.path.exists("CLIP"): gitclone("https://github.com/openai/CLIP") sys.path.append(f'{PROJECT_DIR}/CLIP') try: from guided_diffusion.script_util import create_model_and_diffusion except: - if os.path.exists("guided-diffusion") is not True: + if not os.path.exists("guided-diffusion"): gitclone("https://github.com/crowsonkb/guided-diffusion") sys.path.append(f'{PROJECT_DIR}/guided-diffusion') try: from resize_right import resize except: - if os.path.exists("resize_right") is not True: + if not os.path.exists("ResizeRight"): gitclone("https://github.com/assafshocher/ResizeRight.git") sys.path.append(f'{PROJECT_DIR}/ResizeRight') try: import py3d_tools except: - if os.path.exists('pytorch3d-lite') is not True: + if not os.path.exists('pytorch3d-lite'): gitclone("https://github.com/MSFTserver/pytorch3d-lite.git") sys.path.append(f'{PROJECT_DIR}/pytorch3d-lite') try: from midas.dpt_depth import DPTDepthModel except: - if os.path.exists('MiDaS') is not True: + if not os.path.exists('MiDaS'): gitclone("https://github.com/isl-org/MiDaS.git") - if os.path.exists('MiDaS/midas_utils.py') is not True: + if not os.path.exists('MiDaS/midas_utils.py'): shutil.move('MiDaS/utils.py', 'MiDaS/midas_utils.py') if not os.path.exists(f'{model_path}/dpt_large-midas-2f21e586.pt'): wget("https://github.com/intel-isl/DPT/releases/download/1_0/dpt_large-midas-2f21e586.pt", model_path) sys.path.append(f'{PROJECT_DIR}/MiDaS') try: - sys.path.append(PROJECT_DIR) + sys.path.append(f'{PROJECT_DIR}/disco-diffusion') import disco_xform_utils as dxf except: - if os.path.exists("disco-diffusion") is not True: + if not os.path.exists("disco-diffusion"): gitclone("https://github.com/alembics/disco-diffusion.git") - # Rename a file to avoid a name conflict.. - if os.path.exists('disco_xform_utils.py') is not True: - shutil.move('disco-diffusion/disco_xform_utils.py', 'disco_xform_utils.py') - sys.path.append(PROJECT_DIR) + sys.path.append(f'{PROJECT_DIR}/disco-diffusion') import torch from dataclasses import dataclass @@ -1884,7 +1881,7 @@ if animation_mode == "Video Input": f.unlink() except: print('') - vf = f'"select=not(mod(n\,{extract_nth_frame}))"' + vf = f'select=not(mod(n\,{extract_nth_frame}))' subprocess.run(['ffmpeg', '-i', f'{video_init_path}', '-vf', f'{vf}', '-vsync', 'vfr', '-q:v', '2', '-loglevel', 'error', '-stats', f'{videoFramesFolder}/%04d.jpg'], stdout=subprocess.PIPE).stdout.decode('utf-8') #!ffmpeg -i {video_init_path} -vf {vf} -vsync vfr -q:v 2 -loglevel error -stats {videoFramesFolder}/%04d.jpg