Answer the question
In order to leave comments, you need to log in
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")
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(),
])
Answer the question
In order to leave comments, you need to log in
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 questionAsk a Question
731 491 924 answers to any question