Categories
Misc

uploading app with TensorFlow filter to Heroku cause memory exceeded

Recently I’ve uploaded an application to Heroku with TensorFlow,

the problem is the basic memory that you get from Heroku is 512MB,

which causes the server to crash after loading images into the TensorFlow model when the images are high quality.

Process running mem=934M(182.5%)

Error R14 (Memory quota exceeded)

Process running mem=1108M(216.5%)

Error R15 (Memory quota vastly exceeded)

Then, a few times I exceeded over 1.2GB when using this model, so I bought 1GB.And then it used over 2.2GB

CODE:

import tensorflow_hub

import tensorflow

import numpy

import cv2

model = hub.load(‘https://tfhub.dev/google/magenta/arbitrary-image-stylization-v1-256/2‘)

def load_image(img_path):

img = tensorflow.io.read_file(img_path)

img = tensorflow.image.decode_image(img, channels=3)

img = tensorflow.image.convert_image_dtype(img, tf.tensorflow)

img = img[tensorflow.newaxis, :]

return img

def stylize_img(content_image_path,style_image_path):

content_image = load_image(content_image_path)

style_image = load_image(style_image_path)

cv2.imwrite(‘styled_img.jpg’, cv2.cvtColor(np.squeeze(stylized_image)*255, cv2.COLOR_BGR2RGB))

img = tensorflow.io.read_file(‘styled_img.jpg’)

remove(‘styled_img.jpg’)

return img

how can I solve the memory issue?

submitted by /u/Open-Glove-5238
[visit reddit] [comments]

Leave a Reply

Your email address will not be published.