I am trying to make a classification docker container, but here i am putting a short code. The issue is that docker is not able to take the image folder as input. Here is Dockerfile
FROM pytorch/pytorch:1.6.0-cuda10.1-cudnn7-runtime
RUN apt-get update && apt-get install -y --no-install-recommends \
# we have found python3.7 in base docker
python3-pip \
python3-setuptools \
build-essential \
&& \
apt-get clean && \
python -m pip install --upgrade pip
WORKDIR /workspace
COPY inference.py /workspace
ENTRYPOINT ["python", "inference.py"]
Here is inference.py
file
from glob import glob
import torch
import os
print(os.getcwd())
def main():
parser = argparse.ArgumentParser()
parser.add_argument("-i", '--input_folder', required=True)
args = parser.parse_args()
#load data
images = sorted(glob("{}/*.nii.gz".format(args.input_folder)))
data_dicts = [
{"image": image_name}
for image_name in images
]
print('number of images',len(data_dicts))
print(torch.cuda.get_device_name(0))
if __name__ == "__main__":
main()
Using build command i build docker image docker build -t test .
This is how i am running docker run --gpus all test -i=images
The folder images
is in current directoy. What i am expecting to print the number of images. When i run the image using docker run --gpus all test -i images
it print following
/workspace
number of images 0
NVIDIA GeForce GTX 1060
You need to give the container access to your images folder by mapping it into the container filesystem as a volume. You do that using the -v
option on the docker run
command.
If your images are in the images
folder on your computer and the container expects them in the /workspace/images
folder, you'd map it like this
docker run --gpus all -v $(pwd)/images:/workspace/images test -i images
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.