28
loading...
This website collects cookies to deliver better user experience
@app.route("/")
def homepage():
return render_template("index.html", title="JUST WORK")
@app.route('/post', methods=['GET', 'POST'])
@cross_origin(origin='*',headers=['Content-Type','Authorization'])
def post():
generator, kp_detector = load_checkpoints(config_path='config/vox-256.yaml', checkpoint_path='../vox-cpk.pth.tar', cpu=True) # for gpu specify as false
print("generator done")
predictions = make_animation(source_image=image,driving_video=driving_video, generator=generator, kp_detector=kp_detector, relative=True, cpu=True
) # for gpu specify as false
imageio.mimsave('generatedVideo.mp4', [img_as_ubyte(frame) for frame in predictions], fps=fps)
If you followed the above, you can test it locally and see some nice results, here's an example test script & the result
import requests
resp = requests.post("http://localhost:5000/post",
files={"image": open('02.png','rb'), # 94kb file
"video": open('test.mp4','rb') # 10secs vid
})
## output generation took 03m:03s on cpu (AMD ryzen 7 4800HS)
## for best result use a gpu
FROM nvcr.io/nvidia/cuda:10.0-cudnn7-runtime-ubuntu18.04
RUN DEBIAN_FRONTEND=noninteractive apt-get -qq update \
&& DEBIAN_FRONTEND=noninteractive apt-get -qqy install python3-pip ffmpeg git less nano libsm6 libxext6 libxrender-dev \
&& rm -rf /var/lib/apt/lists/*
COPY . /app/
WORKDIR /app
RUN pip3 install --upgrade pip
RUN pip3 install \
https://download.pytorch.org/whl/cu100/torch-1.0.0-cp36-cp36m-linux_x86_64.whl \
git+https://github.com/1adrianb/face-alignment \
-r requirements.txt
ENTRYPOINT [ "python3" ]
CMD [ "app.py" ]
### requirements.txt
imageio
imageio-ffmpeg
matplotlib
numpy
pandas
python-dateutil
pytz
PyYAML
scikit-image
scikit-learn
scipy
torch
torchvision
tqdm
IPython
flask
flask_cors
requests
NB: The best thing to do would be to edit the dockerfile and requirements.txt(can be seen above) then add the app.py to a forked version of this repo so the container image can be built successfully
gcloud config set project [PROJECT_ID]
gcloud builds submit --tag gcr.io/[PROJECT_ID]/chosen-image-name
Under machine configuration have a minimum of v8CPUs to run the container( A GPU would have been ideal but the model was built with torch 1.0 so there are compatibility issues for the available configurations)
Check the container and specify the address of your container. (also check all the boxes under advanced)
Specify 30gb as the size of the container.
Allow http traffic for the firewall.
For the sake of this example go and edit this firewall http rule to allow all ports to access the IP.