Showing posts with label Image Processing. Show all posts
Showing posts with label Image Processing. Show all posts

Friday, December 9, 2022

Get the output of each layer in Neural network

Lets Consider following simple neural network

import keras.backend as K

from keras.models import Model
from keras.layers import Input, Dense

input_layer = Input((10,))

layer_1 = Dense(10)(input_layer)
layer_2 = Dense(20)(layer_1)
layer_3 = Dense(5)(layer_2)

output_layer = Dense(1)(layer_3)

model = Model(inputs=input_layer, outputs=output_layer)
# some random input
import numpy as np
features = np.random.rand(100,10)
and consider this model is trained

# With a Keras function get the ouputs of all the layers
get_all_layer_outputs = K.function([model.layers[0].input],
                                  [l.output for l in model.layers[0:]])

layer_output = get_all_layer_outputs([features]) # return the same thing

#layer_output is a list of all layers outputs

#if the model is trained you will get the output for input with trained weights other wise 
it will give outout with initial weights

Thursday, October 25, 2018

Save an Image to a folder

import cv2
import os
os.chdir("D:\\NeuralNetwork")
cv2.imwrite('test.png',img)

Wednesday, October 24, 2018

Viewing the Intensity matrix of an image

  1. from skimage import io, viewer
  2. img = io.imread('test.jpg', as_grey=True) # load the image as grayscale
  3. print 'image matrix size: ', img.shape # print the size of image
  4. print '\n First 5 columns and rows of the image matrix: \n', img[:5,:5]*255
  5. viewer.ImageViewer(img).show() # plot the image

Wednesday, August 8, 2018

Display an image

import cv2
image = cv2.imread("D:\Hand.jpg")
cv2.imshow("Diplayed..", image )
cv2.waitKey(1000)