I
I
Ivan Ivanoff2020-04-24 16:09:49
Python
Ivan Ivanoff, 2020-04-24 16:09:49

Convolutional network - load image and save convolution - how?

Hello!
I'm a beginner in Python and tensorflow, and this task appeared:
Take an image and get a convolution on it, and save it for further work, and I just can't do it.
What I do:
functions for loading an image

def preprocess_image(image):
  image = tf.image.decode_jpeg(image, channels=3)
  image = tf.image.resize(image, [192, 192])
  image /= 255.0  # normalize to [0,1] range

  return image

def load_and_preprocess_image(path):
  image = tf.io.read_file(path)
  return preprocess_image(image)
x = load_and_preprocess_image("./1.jpg")


created the model:
model = Sequential([
    Conv2D(16, 3, padding='same', activation='relu', input_shape=(192, 192 ,3)),
    MaxPooling2D(),
    Conv2D(32, 3, padding='same', activation='relu'),
    MaxPooling2D(),
    Conv2D(64, 3, padding='same', activation='relu'),
    MaxPooling2D(),
    Flatten(),
])


And what to do with it further - I do not understand.
It is necessary to cram the image into this model, get an array of numbers at the output and save it to a text file.
Please help!
Thank you in advance

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Sokolov, 2020-04-24
@Thoth777

The model has not yet been trained. What for at once through it to drive a picture?

import json

result = model.predict(x) # это будет массив Numpy
lists = result.tolist()
with fopen('my_result.json', 'w') as fp:
    json.dump(lists, fp)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question