Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

Cover image for Deploying the Model from BigQuery
Cris Crawford
Cris Crawford

Posted on • Edited on

Deploying the Model from BigQuery

This didn't go so well. Well actually it did! I'm editing this post to say that I found a Dockerfile that worked on my Macbook Pro with an M1 chip. First of all, I had to copy the machine learning model that I created inthe previous post from BigQuery to a Google cloud storage bucket. In the video, the instructor said to usegcloud auth login and thenbq --project_id taxi-rides-ny extract -m nytaxi.tip_model gs://taxi_ml_model/tip_model (his bucket and model). I did this, but I got the error message:

BigQuery error in extract operation: Access Denied: Project data-engineering-2024: User does not have bigquery.jobs.create permission in projectdata-engineering-2024.
Enter fullscreen modeExit fullscreen mode

After trying to set permissions for bigquery.jobs.create for about ten minutes, I gave up and went to BigQuery, selected the model, and exported it to cris-crawfords-week3-bucket/tip_model.

Now the fun began. I set up a directory for the model on my computer, following the commands the instructor used.

% mkdir /tmp/model% gsutil cp -r gs://cris-crawfords-week3-bucket/tip_model /tmp/model% mkdir -p serving_dir/tip_model/1% cp -r /tmp/model/tip_model/\* serving_dir/tip_model/1
Enter fullscreen modeExit fullscreen mode

So far so good. Now I tried to make a Dockerfile with tensorflow. I pulled a Dockerfile from Docker Hub, and tried to run it:

docker pull tensorflow/servingdocker run -p 8500:8500 -p 8501:8501 --mount type=bind,source=`pwd`/serving_dir/tip_model,target=/model -e MODEL_NAME=tip_model -t tensorflow/serving &
Enter fullscreen modeExit fullscreen mode

This didn't work, because the Dockerfile for Mac, which I have, expected an Intel chip, which I don't have. I have an Apple chip. After about an hour of frustration I asked what I could do on the Slack channel. I found another Dockerfile that I could pull from Docker Hub: bitnami/tensorflow-serving. I did this, but more errors, this time about the directory "model". I had to use model-data, not model. Finally I got it to run:

docker pull bitnami/tensorflow-serving:latestdocker run -p 8500:8500 -p 8501:8501 --mount type=bind,source=`pwd`/serving_dir/tip_model,target=/bitnami/model-data -e MODEL_NAME=tip_model -t bitnami/tensorflow-serving &
Enter fullscreen modeExit fullscreen mode

The next and final step was to run a command that would ask the model for a prediction.

curl -d '{"instances": [{"passenger_count":1, "trip_distance":12.2, "pu_location_id":"193", "do_location_id":"264", "payment_type":"2","fare_amount":20.4,"tolls_amount":0.0}]}' -X POST http://localhost:8501/v1/bitnami/model-data/tip_model:predict
Enter fullscreen modeExit fullscreen mode

This led to the error"Malformed request: GET /v1/bitnami/model-data/tip_model". After struggling for about two hours, I gave up. I looked at the model, and it looked like everything was there. For a linear regression, the model consists of the coefficients of the inputs, so it should be small, which it was. The way I spelled the inputs matched the variables in the model. I looked at the example on Google cloud, and it looked correct. It matched what the instructor had in the video.

I learned:

  • That you can create an ML model on BigQuery from a data set.
  • You can deploy the model using Tensorflow.
  • The Tensorflow Dockerfile doesn't work on Macs with an Apple chip (all of the new Macs have an Apple chip)
  • I could pull a Dockerfile from Docker Hub that did run tensorflow on a Mac with an Apple chip.

For now, I'm admitting defeat. But I learned a lot. If I have time, I'll go back and try to figure out what went wrong.

So the good people on the Slack for Data Talks Club's Data Engineering Zoomcamp pointed me to the Dockerfile emacski/tensorflow-serving. Because I already had my serving_dir directory set up with the model in it, all I had to do was typedocker pull emacski/tensorflow-serving and then docker run. Here's my modified command:

docker run -p 8500:8500 -p 8501:8501 --mount type=bind,source=`pwd`/serving_dir/tip_model,target=/emacski/model -e MODEL_NAME=tip_model -t emacski/tensorflow-serving &
Enter fullscreen modeExit fullscreen mode

Then run the curl command:

curl -d '{"instances": [{"passenger_count":1, "trip_distance":12.2, "pu_location_id":"193", "do_location_id":"264", "payment_type":"2","fare_amount":20.4,"tolls_amount":0.0}]}' -X POST http://localhost:8501/v1/emacski/model/tip_model:predict
Enter fullscreen modeExit fullscreen mode

And it worked! I got a prediction for the tip amount. So I remain undefeated!

Top comments(0)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

I wrote computational geometry software for computer aided design systems in C and C++ for many years, and I'm now learning new things.
  • Location
    Boston, Massachusetts
  • Joined

More fromCris Crawford

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp