I’m building an AWS Lambda with Python 3.10 & detectron2
in it and it’s not working at all.
# Use the Python 3.10 base image for AWS Lambda
```
FROM public.ecr.aws/lambda/python:3.10 AS build
```
# Set environment variables
```
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1
ENV LAMBDA_TASK_ROOT /var/task
```
# Set working directory
`WORKDIR ${LAMBDA_TASK_ROOT} `
# Install system dependencies for detectron2 and other required libraries
```
RUN yum update -y
&& yum install -y
git
gcc
gcc-c++
make
cmake
wget
libpng-devel
libjpeg-devel
libtiff-devel
zlib-devel
mesa-libGL
mesa-libGL-devel
opencv
tar
&& yum clean all
```
# Install pip and upgrade it to the latest version
`RUN pip install --upgrade pip `
# Step 1: Install PyTorch and torchvision globally first so that detectron2 can find torch
`RUN pip install torch torchvision `
# Step 2: Install detectron2 from GitHub after torch is installed
`RUN pip install 'git+https://github.com/facebookresearch/detectron2.git' `
# Step 3: Install other required dependencies (cython, pycocotools, etc.)
`RUN pip install cython pycocotools `
# Step 4: Move all installed packages into ${LAMBDA_TASK_ROOT}
`RUN pip install --target "${LAMBDA_TASK_ROOT}" torch torchvision detectron2 cython pycocotools `
# Step 5: Install additional dependencies from requirements.txt
` COPY requirements.txt . RUN pip install --target "${LAMBDA_TASK_ROOT}" -r requirements.txt`
# Clean up the build to reduce image size
`RUN rm -rf /var/cache/yum && rm -rf /tmp/* `
# Expose necessary ports (optional)
`EXPOSE 8080 `
# Command to run the Lambda function
`CMD ["app.lambda_handler"]
This is what my dockerfile looks like but currently im facing
"No module named torch"
An error in step 2, which is installing detectron2
. Is there anyone who has already built this thing, kindly share your thoughts.