diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..512431e --- /dev/null +++ b/Dockerfile @@ -0,0 +1,28 @@ +# Select the base image +FROM python:3.10 + +# Set the working directory +WORKDIR /code + +# Copy the requirements file +COPY ./requirements.txt /code/requirements.txt + +# Copy the source code +COPY ./api /code/api +COPY ./cifar.h5 /code/cifar.h5 +COPY ./api/ /code/api/ +COPY ./cifar10/ /code/cifar10/ + + +# Install ffmpeg +RUN apt-get update -y +RUN apt-get install ffmpeg libsm6 libxext6 libxext6 -y + +# Install the dependencies +RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt + + +# Expose the port +EXPOSE 80 + +CMD ["uvicorn", "api:app", "--host", "0.0.0.0", "--port", "80"] \ No newline at end of file diff --git a/README.md b/README.md index 502c4da..7b49514 100644 --- a/README.md +++ b/README.md @@ -13,12 +13,12 @@ Resumen First architecture tested ![](docs/first_result.jpg) [Complete graphics (Basic)](https://tensorboard.dev/experiment/82Hg4m0YQ1uMWkw69qSv6w/#scalars) - [Complete graphics (Best)](https://tensorboard.dev/experiment/jhqlZ8dBRtOzxMm9o8wQcw/#scalars) -![Transfer learning result](./docs/transfer_learning_result.jpg) [Architecture using transfer learning](docs/model_plot3.png) +![Transfer learning result](./docs/transfer_learning_result.jpg) + [Complete Graphics (Transfer LEarning)](https://tensorboard.dev/experiment/o7f6pvAMT3KSpX88ge0h1Q/#scalars) diff --git a/api/__init__.py b/api/__init__.py new file mode 100644 index 0000000..02cbd73 --- /dev/null +++ b/api/__init__.py @@ -0,0 +1,25 @@ +from fastapi import FastAPI + +app = FastAPI( + title="Cifar 10 Api", + description=''' + This is a simple api for cifar 10 dataset. + + The classes trainer are the next: + + - airplane + - automobile + - bird + - cat + - deer + - dog + - frog + - horse + - ship + - truck + ''', + version="1.0", + +) + +from .views import * \ No newline at end of file diff --git a/api/views.py b/api/views.py new file mode 100644 index 0000000..9717de7 --- /dev/null +++ b/api/views.py @@ -0,0 +1,38 @@ +from . import app +from fastapi import UploadFile, File, HTTPException +import cv2 +from cifar10 import Model +import numpy as np + +model = Model() + +ALLOW_EXTENSION = ['jpg', 'jpeg', 'png', ] + +@app.get('/') +def index(): + return {'message': 'Hello, World!'} + +@app.post('/analyze_image') +async def analyze_image(file: UploadFile = File(...)): + ''' + Analyze image and return the result + + Args: + file (UploadFile): image file + + Returns: + dict: result + ''' + extension = file.filename.split('.')[-1].lower() + + if extension not in ALLOW_EXTENSION: + raise HTTPException(status_code=400, detail='File extension not allowed') + + contents = await file.read() + nparr = np.fromstring(contents, np.uint8) + img = cv2.imdecode(nparr, cv2.IMREAD_COLOR) + img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB) + + result = model.predict(img) + + return {'predict': result} \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index 6f236da..8721dcd 100644 --- a/requirements.txt +++ b/requirements.txt @@ -5,4 +5,9 @@ opencv-python ipykernel #devs -matplotlib \ No newline at end of file +matplotlib + +#api +fastapi +uvicorn +python-multipart \ No newline at end of file diff --git a/requirements_macos.txt b/requirements_macos.txt index c33ff6a..142de00 100644 --- a/requirements_macos.txt +++ b/requirements_macos.txt @@ -7,4 +7,9 @@ ipykernel #dev -matplotlib \ No newline at end of file +matplotlib + +#api +fastapi +uvicorn +python-multipart \ No newline at end of file