Skip to content

Commit

Permalink
update readme, update docker, remove duplicated code and cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
jeortizquan committed Oct 11, 2024
1 parent ab5ecb7 commit 1ff511a
Show file tree
Hide file tree
Showing 11 changed files with 43 additions and 138 deletions.
17 changes: 15 additions & 2 deletions README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,7 @@ add dependency in your project
<dependency>
<groupId>eu.europeana.metis.image.enhancement</groupId>
<artifactId>metis-image-enhancer-client</artifactId>
<version>0.0.1-SNAPSHOT</version>
<scope>compile</scope>
<version>1</version>
</dependency>
````
### properties
Expand All @@ -102,6 +101,20 @@ api.url = http://localhost:5050
connect.timeout = 300
read.timeout = 300
```
#### command line stand alone script
If you only want to use the image processing without the API, you can invoke this
from the command line, using the script directly.

```
python ./metis-image-enhancer-python-rest/src/main/mie.py -i image_input.jpg -o image_output.jpg
```


## General limitations
Why this AI python model runs as a script? in this iteration the python model cannot be held
in memory otherwise you will get an Out of Memory. The model in python of image processing
doesn't free the resources every time.
Steps of usage: load, process, get results, discard, repeat again.

#### See demo project
run docker image previous to execute the demo app and then execute the following command in the cloned folder of
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
*/
public class ImageEnhancerWorker {
private static final Logger LOGGER = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
private static final boolean IS_FILTER_ENABLED = false;
private final ImageEnhancer imageEnhancer;

/**
Expand Down Expand Up @@ -70,7 +71,9 @@ public byte[] enhance(byte[] input) {

final String format = getImageFormat(input);

// ImageIO.write(sharpen(image), format, baos);
if (IS_FILTER_ENABLED) {
ImageIO.write(sharpen(image), format, baos);
}
ImageIO.write(image, format, baos);
} catch (IOException e) {
LOGGER.error("enhancing the image", e);
Expand Down

This file was deleted.

1 change: 1 addition & 0 deletions metis-image-enhancer-demo/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/src/main/resources/application.properties
README.MD
target/
!.mvn/wrapper/maven-wrapper.jar
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
isr.api.url = http://localhost:8080
isr.connect.timeout = 300
isr.read.timeout = 300
isr.script = ../metis-image-enhancer-python-script/src/main/mie.py
isr.script = ../metis-image-enhancer-python-rest/src/main/mie.py
worker.service.type = api
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
isr.api.url = http://localhost:8080
isr.connect.timeout = 300
isr.read.timeout = 300
isr.script = ../metis-image-enhancer-python-script/src/main/mie.py
isr.script = ../metis-image-enhancer-python-rest/src/main/mie.py
worker.service.type = script
25 changes: 15 additions & 10 deletions metis-image-enhancer-python-rest/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,21 +1,26 @@
FROM ubuntu:22.04
FROM ubuntu:24.10

RUN apt-get update && apt-get upgrade -y
RUN apt-get install git -y
RUN apt-get install python3-pip -y
RUN apt install python3 python3-pip python3-venv python3-setuptools python3-pil python3-filetype python3-flask python3-waitress -y
RUN mkdir flask-app && cd flask-app
RUN python3 -m venv flask-venv
RUN . flask-venv/bin/activate

RUN pip3 install --upgrade pip
RUN pip3 install filetype
RUN pip3 install Flask
RUN pip3 install waitress
RUN pip3 install uuid
RUN pip3 install tensorflow==2.13.0
RUN flask-venv/bin/pip3 install --upgrade pip
RUN flask-venv/bin/pip3 install filetype
RUN flask-venv/bin/pip3 install Flask
RUN flask-venv/bin/pip3 install waitress
RUN flask-venv/bin/pip3 install uuid
RUN flask-venv/bin/pip3 install pillow
RUN flask-venv/bin/pip3 install tensorflow==2.17.0 numpy==1.26.0

RUN git clone https://github.com/idealo/image-super-resolution.git \
&& cd image-super-resolution \
&& git checkout v2.2.0 \
&& sed -i 's/tensorflow==2.0.0/tensorflow==2.13.0/' setup.py \
&& sed -i 's/tensorflow-gpu==2.0.0/tensorflow-gpu==2.13.0/' setup.py \
&& sed -i 's/numpy/numpy==1.26.0/' setup.py \
&& sed -i 's/tensorflow==2.0.0/tensorflow==2.17.0/' setup.py \
&& sed -i 's/tensorflow-gpu==2.0.0/tensorflow-gpu==2.17.0/' setup.py \
&& python3 setup.py install

COPY src/main/api.py .
Expand Down
10 changes: 5 additions & 5 deletions metis-image-enhancer-python-rest/src/main/mie.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
# Arguments
def parameters(argv):
arg_help = "{0} -i <input> -o <output>".format(argv[0])
params = dict();
params = dict()

try:
opts, args = getopt.getopt(argv[1:], "hio:v", ["help", "input=", "output="])
opts = getopt.getopt(argv[1:], "hio:v", ["help", "input=", "output="])
except:
print(arg_help)
sys.exit(2)
Expand Down Expand Up @@ -84,9 +84,9 @@ def main(params):
# elapsed time
print ('loading model elapsed time: ',end - start)
# Declare the input and output file locations
inputFile = r'{0}'.format(params['arg_input']).strip()
outputFile = r'{0}'.format(params['arg_output']).strip()
enhance(inputFile, outputFile, model)
input_file = r'{0}'.format(params['arg_input']).strip()
output_file = r'{0}'.format(params['arg_output']).strip()
enhance(input_file, output_file, model)

if __name__ == "__main__":
main(parameters(sys.argv))
19 changes: 0 additions & 19 deletions metis-image-enhancer-python-script/pom.xml

This file was deleted.

92 changes: 0 additions & 92 deletions metis-image-enhancer-python-script/src/main/mie.py

This file was deleted.

3 changes: 1 addition & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,9 @@
<module>metis-image-enhancer-demo</module>
<module>metis-image-enhancer-client</module>
<module>metis-image-enhancer-python-rest</module>
<module>metis-image-enhancer-python-script</module>
</modules>
<properties>
<java.version>11</java.version>
<java.version>21</java.version>
<version.spring>2.7.11</version.spring>
<version.junit>5.9.3</version.junit>
<version.mockito>5.4.0</version.mockito>
Expand Down

0 comments on commit 1ff511a

Please sign in to comment.