0

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

1 Answer 1

1

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
Sign up to request clarification or add additional context in comments.

4 Comments

still it print number of images 0
but if i do python3 inference.py -i images without docker, it shows me number of images
this helps docker run --gpus all -v $PWD/images:/workspace/images test -i images
Yes, sorry. The host path needs to be absolute.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.