openfaas / faas

OpenFaaS - Serverless Functions Made Simple
https://www.openfaas.com
MIT License
24.75k stars 1.92k forks source link

How do I use a tensorflow base image in the Dockerfile template? Is it possible? #1837

Open prateeumich opened 2 months ago

prateeumich commented 2 months ago

My actions before raising this issue

Why do you need this?

Who is this for?

What company is this for? Are you listed in the ADOPTERS.md file?

Expected Behaviour

Current Behaviour

I am trying to install tensorflow inside the docker container, is it possible to use a tensorflow base image or no? I can see we are only using alpine linux as the base image

Are you a GitHub Sponsor (Yes/No?)

NO Check at: https://github.com/sponsors/openfaas

List All Possible Solutions and Workarounds

Which Solution Do You Recommend?

Steps to Reproduce (for bugs)

1. 2. 3. 4.

Context

## Your Environment
alexellis commented 2 months ago

Hi @prateeumich of course, you can do whatever you want in a Dockerfile.

Can you share what do you have so far?

What programming language are you trying to use? Python?

prateeumich commented 2 months ago

this is my dockerfile

**FROM ghcr.io/openfaas/classic-watchdog:0.2.3 as watchdog

FROM tensorflow/tensorflow:latest-gpu

RUN mkdir -p /home/app

COPY --from=watchdog /fwatchdog /usr/bin/fwatchdog RUN chmod +x /usr/bin/fwatchdog

Add non root user

RUN addgroup -S app && adduser app -S -G app

Add non root user

RUN groupadd -r app && useradd -r -g app app

RUN chown app /home/app COPY program.py .

WORKDIR /home/app

USER app

Populate example here - i.e. "cat", "sha512sum" or "node index.js"

ENV fprocess="cat"

Set to true to see request in function logs

ENV write_debug="false"

EXPOSE 8080

HEALTHCHECK --interval=3s CMD [ -e /tmp/.lock ] || exit 1

CMD ["fwatchdog"]**

I have written a matmul program using tensorflow and python

import tensorflow as tf

# Check if GPU is available
if tf.test.is_gpu_available():
    print("GPU is available")
else:
    print("GPU is NOT available")

# Define a simple TensorFlow computation graph
a = tf.constant(3.0)
b = tf.constant(4.0)
c = tf.add(a, b)

# Create a TensorFlow session
with tf.Session() as sess:
    # Execute the computation graph
    result = sess.run(c)
    print("Result:", result)

I was able to up the function but when I was invoking the function there was no output in the command line

Faas

prateeumich commented 2 months ago

Also, when is the copy step correct or is it why it isn't running the program?