152 - How to visualize convolutional filter outputs in your deep learning model?

  Рет қаралды 34,051

DigitalSreeni

DigitalSreeni

Күн бұрын

Пікірлер
@fadilyassin4597
@fadilyassin4597 3 жыл бұрын
thank you I urge any one who want to understand machine learning to see all the videos because Mr seerni is covering the process in a way that it is very essential to any one who wants to understand ML just look at the toics and see what I mean
@MaralSheikhzadeh
@MaralSheikhzadeh 2 жыл бұрын
I am learning so much from you in the two days I found your channel! Thank you:)
@PUBUDUCG
@PUBUDUCG 2 жыл бұрын
This is very valuable when model debugging is necessary . . . . !
@rhezapaleva7169
@rhezapaleva7169 2 жыл бұрын
Thank you very much, this is really help me to visualize the process of the cnn layer
@DigitalSreeni
@DigitalSreeni 2 жыл бұрын
Glad it helped!
@Ahmetkumas
@Ahmetkumas 4 жыл бұрын
Thank you it's a very useful video for who wants to dig into more. Can you make more and deeper videos for different problems on semantic segmentation on U-net or etc
@DigitalSreeni
@DigitalSreeni 4 жыл бұрын
Sure thing!
@ausialfrai3335
@ausialfrai3335 4 жыл бұрын
Thank you Sreeni for the great video, it came out at the right time :)
@DigitalSreeni
@DigitalSreeni 4 жыл бұрын
My pleasure 😊
@RizwanAli-jy9ub
@RizwanAli-jy9ub 4 жыл бұрын
every video is a gem
@DigitalSreeni
@DigitalSreeni 4 жыл бұрын
Thanks :)
@VivekKumar-zw1wx
@VivekKumar-zw1wx 3 жыл бұрын
Sir there are 128 filter in the 3rd convolution layer then why it is showing the output for only 64 filters...
@juanodonnell
@juanodonnell 2 жыл бұрын
You say that by stating the conv_layer_index (1,3,6) command you will be working with the 6th-ish first layers, but the model that gets called is a totally different one, actually the 3 conv2d counting from the end, thats why the shape is different than the prev examples. It is a confusing example.
@qusayhamad7243
@qusayhamad7243 2 жыл бұрын
Thank you Sir it was too helpful and clear
@seaniam
@seaniam 3 жыл бұрын
I never thought about simply cutting the model and predicting on that......seems obvious now. thanks
@DigitalSreeni
@DigitalSreeni 3 жыл бұрын
You bet!
@VivekKumar-zw1wx
@VivekKumar-zw1wx 3 жыл бұрын
@Sean their is 128 filters in 3rd convolution layer then why it is showing the output only for 64 filters
@seaniam
@seaniam 3 жыл бұрын
​@@VivekKumar-zw1wx as Sreeni chose to only show 64 images in the plot lines 77 + 78 -> number of rows and columns are defined (8,8) line 79 -> n_filters = cols * rows # this is used to determine number of loops (8*8 = 64) so n_filters determines how many images to pull from filters - if you want more change that same idea on line 116 -> range(1,columns*rows +1)
@ahmedalaa4699
@ahmedalaa4699 2 жыл бұрын
Thank you very much for your amazing tutorial
@iangleeson3338
@iangleeson3338 Жыл бұрын
Thanks. What happens if I’m just predicting something like age? How can I apply this?
@spider853
@spider853 Жыл бұрын
it's the same process as described in this video, you'll probably get filters that extract the wrinkless and so on
@azaralizadeh3492
@azaralizadeh3492 2 жыл бұрын
Amazing, amazing video. thank you so much
@channelforstream6196
@channelforstream6196 4 жыл бұрын
Thanks was looking for just the thing
@samarafroz9852
@samarafroz9852 4 жыл бұрын
Amazing tutorial sir I'm learning so much from you. Can you please make tutorial on Capsule network for image analysis.
@DigitalSreeni
@DigitalSreeni 4 жыл бұрын
Capsule networks are very new and they only work reliably on simple datasets such as MNIST. It is evolving fast so let us see if they turn into something useful. Thanks for the recommendation though!!
@samarafroz9852
@samarafroz9852 4 жыл бұрын
Welcome sir
@armankarimipy
@armankarimipy 2 жыл бұрын
Thank you it's a veryyyyyyyy useful video for me!
@omrahulpandey
@omrahulpandey 4 жыл бұрын
Sir, how do we do this with the UNet from your earlier video.....I used this code...but it ain't working with this integration..... at the console it shouts..." File "F:\UNet1.py", line 137, in filters, biases = model.layers[1].get_weights() ValueError: not enough values to unpack (expected 2, got 0)" I placed this code just after the model.summary() line......Let me paste the entire code here for your convenience...(leaving the resizing part) #Build the model inputs = tf.keras.layers.Input((IMG_HEIGHT, IMG_WIDTH, IMG_CHANNELS)) s = tf.keras.layers.Lambda(lambda x: x / 255)(inputs) #Contraction path c1 = tf.keras.layers.Conv2D(16, (3, 3), activation='relu', kernel_initializer='he_normal', padding='same')(s) c1 = tf.keras.layers.Dropout(0.1)(c1) c1 = tf.keras.layers.Conv2D(16, (3, 3), activation='relu', kernel_initializer='he_normal', padding='same')(c1) p1 = tf.keras.layers.MaxPooling2D((2, 2))(c1) c2 = tf.keras.layers.Conv2D(32, (3, 3), activation='relu', kernel_initializer='he_normal', padding='same')(p1) c2 = tf.keras.layers.Dropout(0.1)(c2) c2 = tf.keras.layers.Conv2D(32, (3, 3), activation='relu', kernel_initializer='he_normal', padding='same')(c2) p2 = tf.keras.layers.MaxPooling2D((2, 2))(c2) c3 = tf.keras.layers.Conv2D(64, (3, 3), activation='relu', kernel_initializer='he_normal', padding='same')(p2) c3 = tf.keras.layers.Dropout(0.2)(c3) c3 = tf.keras.layers.Conv2D(64, (3, 3), activation='relu', kernel_initializer='he_normal', padding='same')(c3) p3 = tf.keras.layers.MaxPooling2D((2, 2))(c3) c4 = tf.keras.layers.Conv2D(128, (3, 3), activation='relu', kernel_initializer='he_normal', padding='same')(p3) c4 = tf.keras.layers.Dropout(0.2)(c4) c4 = tf.keras.layers.Conv2D(128, (3, 3), activation='relu', kernel_initializer='he_normal', padding='same')(c4) p4 = tf.keras.layers.MaxPooling2D(pool_size=(2, 2))(c4) c5 = tf.keras.layers.Conv2D(256, (3, 3), activation='relu', kernel_initializer='he_normal', padding='same')(p4) c5 = tf.keras.layers.Dropout(0.3)(c5) c5 = tf.keras.layers.Conv2D(256, (3, 3), activation='relu', kernel_initializer='he_normal', padding='same')(c5) #Expansive path u6 = tf.keras.layers.Conv2DTranspose(128, (2, 2), strides=(2, 2), padding='same')(c5) u6 = tf.keras.layers.concatenate([u6, c4]) c6 = tf.keras.layers.Conv2D(128, (3, 3), activation='relu', kernel_initializer='he_normal', padding='same')(u6) c6 = tf.keras.layers.Dropout(0.2)(c6) c6 = tf.keras.layers.Conv2D(128, (3, 3), activation='relu', kernel_initializer='he_normal', padding='same')(c6) u7 = tf.keras.layers.Conv2DTranspose(64, (2, 2), strides=(2, 2), padding='same')(c6) u7 = tf.keras.layers.concatenate([u7, c3]) c7 = tf.keras.layers.Conv2D(64, (3, 3), activation='relu', kernel_initializer='he_normal', padding='same')(u7) c7 = tf.keras.layers.Dropout(0.2)(c7) c7 = tf.keras.layers.Conv2D(64, (3, 3), activation='relu', kernel_initializer='he_normal', padding='same')(c7) u8 = tf.keras.layers.Conv2DTranspose(32, (2, 2), strides=(2, 2), padding='same')(c7) u8 = tf.keras.layers.concatenate([u8, c2]) c8 = tf.keras.layers.Conv2D(32, (3, 3), activation='relu', kernel_initializer='he_normal', padding='same')(u8) c8 = tf.keras.layers.Dropout(0.1)(c8) c8 = tf.keras.layers.Conv2D(32, (3, 3), activation='relu', kernel_initializer='he_normal', padding='same')(c8) u9 = tf.keras.layers.Conv2DTranspose(16, (2, 2), strides=(2, 2), padding='same')(c8) u9 = tf.keras.layers.concatenate([u9, c1], axis=3) c9 = tf.keras.layers.Conv2D(16, (3, 3), activation='relu', kernel_initializer='he_normal', padding='same')(u9) c9 = tf.keras.layers.Dropout(0.1)(c9) c9 = tf.keras.layers.Conv2D(16, (3, 3), activation='relu', kernel_initializer='he_normal', padding='same')(c9) outputs = tf.keras.layers.Conv2D(1, (1, 1), activation='sigmoid')(c9) model = tf.keras.Model(inputs=[inputs], outputs=[outputs]) model.compile(optimizer='adam', loss='binary_crossentropy', metrics=['accuracy',tf.keras.metrics.MeanIoU(num_classes=2)]) model.summary() ############################################################################ #Understand the filters in the model #Let us pick the first hidden layer as the layer of interest. layer = model.layers #Conv layers at 1, 3, 6, 8, 11, 13, 15 filters, biases = model.layers[1].get_weights() print(layer[1].name, filters.shape) # plot filters fig1=plt.figure(figsize=(8, 12)) columns = 8 rows = 8 n_filters = columns * rows for i in range(1, n_filters +1): f = filters[:, :, :, i-1] fig1 =plt.subplot(rows, columns, i) fig1.set_xticks([]) #Turn off axis fig1.set_yticks([]) plt.imshow(f[:, :, 0], cmap='gray') #Show only the filters from 0th channel (R) #ix += 1 plt.show() #### Now plot filter outputs #Define a new truncated model to only include the conv layers of interest #conv_layer_index = [1, 3, 6, 8, 11, 13, 15] conv_layer_index = [1, 3, 6] #TO define a shorter model outputs = [model.layers[i].output for i in conv_layer_index] model_short = model(inputs=model.inputs, outputs=outputs) print(model_short.summary()) #Input shape to the model is 224 x 224. SO resize input image to this shape. from keras.preprocessing.image import load_img, img_to_array img = load_img('monalisa.jpg', target_size=(224, 224)) #VGG user 224 as input # convert the image to an array img = img_to_array(img) # expand dimensions to match the shape of model input img = np.expand_dims(img, axis=0) # Generate feature output by predicting on the input image feature_output = model_short.predict(img) columns = 8 rows = 8 for ftr in feature_output: #pos = 1 fig=plt.figure(figsize=(12, 12)) for i in range(1, columns*rows +1): fig =plt.subplot(rows, columns, i) fig.set_xticks([]) #Turn off axis fig.set_yticks([]) plt.imshow(ftr[0, :, :, i-1], cmap='gray') #pos += 1 plt.show() ############################################################################ #Modelcheckpoint checkpointer = tf.keras.callbacks.ModelCheckpoint('model_for_nuclei.h5', verbose=1, save_best_only=True) callbacks = [ tf.keras.callbacks.EarlyStopping(patience=2, monitor='val_loss'), tf.keras.callbacks.TensorBoard(log_dir='logs',histogram_freq=1)] results = model.fit(X_train, Y_train, validation_split=0.1, batch_size=16, epochs=25, callbacks=callbacks) #################################### idx = random.randint(0, len(X_train)) preds_train = model.predict(X_train[:int(X_train.shape[0]*0.9)], verbose=1) preds_val = model.predict(X_train[int(X_train.shape[0]*0.9):], verbose=1) preds_test = model.predict(X_test, verbose=1) preds_train_t = (preds_train > 0.5).astype(np.uint8) preds_val_t = (preds_val > 0.5).astype(np.uint8) preds_test_t = (preds_test > 0.5).astype(np.uint8) ###################################################### # Perform a sanity check on some random training samples ix = random.randint(0, len(preds_train_t)) imshow(X_train[ix]) plt.show() imshow(np.squeeze(Y_train[ix])) plt.show() imshow(np.squeeze(preds_train_t[ix])) plt.show() # Perform a sanity check on some random validation samples ix = random.randint(0, len(preds_val_t)) imshow(X_train[int(X_train.shape[0]*0.9):][ix]) plt.show() imshow(np.squeeze(Y_train[int(Y_train.shape[0]*0.9):][ix])) plt.show() imshow(np.squeeze(preds_val_t[ix])) plt.show() Sir can you please tell me where is the problem...
@DigitalSreeni
@DigitalSreeni 4 жыл бұрын
U-net is not a straight forward constitutional layers, it has down scaling and up scaling path where outputs are concatenated. So you cannot easily visualize outputs as images. You may try visualizing them during the down scaling path.
@abderrahmaneherbadji5478
@abderrahmaneherbadji5478 4 жыл бұрын
Hi Sreeni Many Thanks for this video
@DigitalSreeni
@DigitalSreeni 4 жыл бұрын
My pleasure 😊
@nirajgautam403
@nirajgautam403 3 жыл бұрын
how to print all filter
@kemmounramzy6232
@kemmounramzy6232 Жыл бұрын
Thank you it's a very useful video
@nirajgautam403
@nirajgautam403 3 жыл бұрын
i have 5*5 filter but it print 3*3 filter
@raflyhidayat9687
@raflyhidayat9687 6 ай бұрын
what name this file in github bro?
@guardrepresenter5099
@guardrepresenter5099 3 жыл бұрын
Sir, I copied this code from your GitHub page. But I give an error as follows. tensorflow.python.framework.errors_impl.InvalidArgumentError: Negative dimension size caused by subtracting 2 from 1 for '{{node max_pooling2d_2/MaxPool}} = MaxPool[T=DT_FLOAT, data_format="NHWC", explicit_paddings=[], ksize=[1, 2, 2, 1], padding="VALID", strides=[1, 2, 2, 1]](Placeholder)' with input shapes: [?,1,1,256]. During handling of the above exception, another exception occurred: Traceback (most recent call last): File "C:/Users/Bilen-Intel/PycharmProjects/TenSorFlow/ConvulationLayersVision.py", line 36, in model.add(MaxPooling2D((2, 2), strides=(2, 2))) File "C:\Users\Bilen-Intel\AppData\Local\Programs\Python\Python38\lib\site-packages\tensorflow\python\training\tracking\base.py", line 517, in _method_wrapper result = method(self, *args, **kwargs) File "C:\Users\Bilen-Intel\AppData\Local\Programs\Python\Python38\lib\site-packages\tensorflow\python\keras\engine\sequential.py", line 223, in add output_tensor = layer(self.outputs[0]) File "C:\Users\Bilen-Intel\AppData\Local\Programs\Python\Python38\lib\site-packages\tensorflow\python\keras\engine\base_layer.py", line 951, in __call__ return self._functional_construction_call(inputs, args, kwargs, File "C:\Users\Bilen-Intel\AppData\Local\Programs\Python\Python38\lib\site-packages\tensorflow\python\keras\engine\base_layer.py", line 1090, in _functional_construction_call outputs = self._keras_tensor_symbolic_call( File "C:\Users\Bilen-Intel\AppData\Local\Programs\Python\Python38\lib\site-packages\tensorflow\python\keras\engine\base_layer.py", line 822, in _keras_tensor_symbolic_call return self._infer_output_signature(inputs, args, kwargs, input_masks) File "C:\Users\Bilen-Intel\AppData\Local\Programs\Python\Python38\lib\site-packages\tensorflow\python\keras\engine\base_layer.py", line 863, in _infer_output_signature outputs = call_fn(inputs, *args, **kwargs) File "C:\Users\Bilen-Intel\AppData\Local\Programs\Python\Python38\lib\site-packages\tensorflow\python\keras\layers\pooling.py", line 295, in call outputs = self.pool_function( File "C:\Users\Bilen-Intel\AppData\Local\Programs\Python\Python38\lib\site-packages\tensorflow\python\util\dispatch.py", line 201, in wrapper return target(*args, **kwargs) File "C:\Users\Bilen-Intel\AppData\Local\Programs\Python\Python38\lib\site-packages\tensorflow\python\ops n_ops.py", line 4606, in max_pool return gen_nn_ops.max_pool( File "C:\Users\Bilen-Intel\AppData\Local\Programs\Python\Python38\lib\site-packages\tensorflow\python\ops\gen_nn_ops.py", line 5326, in max_pool _, _, _op, _outputs = _op_def_library._apply_op_helper( File "C:\Users\Bilen-Intel\AppData\Local\Programs\Python\Python38\lib\site-packages\tensorflow\python\framework\op_def_library.py", line 748, in _apply_op_helper op = g._create_op_internal(op_type_name, inputs, dtypes=None, File "C:\Users\Bilen-Intel\AppData\Local\Programs\Python\Python38\lib\site-packages\tensorflow\python\framework\func_graph.py", line 590, in _create_op_internal return super(FuncGraph, self)._create_op_internal( # pylint: disable=protected-access File "C:\Users\Bilen-Intel\AppData\Local\Programs\Python\Python38\lib\site-packages\tensorflow\python\framework\ops.py", line 3528, in _create_op_internal ret = Operation( File "C:\Users\Bilen-Intel\AppData\Local\Programs\Python\Python38\lib\site-packages\tensorflow\python\framework\ops.py", line 2015, in __init__ self._c_op = _create_c_op(self._graph, node_def, inputs, File "C:\Users\Bilen-Intel\AppData\Local\Programs\Python\Python38\lib\site-packages\tensorflow\python\framework\ops.py", line 1856, in _create_c_op raise ValueError(str(e)) ValueError: Negative dimension size caused by subtracting 2 from 1 for '{{node max_pooling2d_2/MaxPool}} = MaxPool[T=DT_FLOAT, data_format="NHWC", explicit_paddings=[], ksize=[1, 2, 2, 1], padding="VALID", strides=[1, 2, 2, 1]](Placeholder)' with input shapes: [?,1,1,256]. Process finished with exit code 1
@christopherhimmel9942
@christopherhimmel9942 9 ай бұрын
I am also getting this error. Any solution?
@hachimbani2674
@hachimbani2674 3 жыл бұрын
Hello, First of all thank you for your videos they helped me so well to improve in this field. I am trying to visualize Receptive fields for a given unit in the pretrained AlexNet model in pytorch. To do that I am using the occlusion method used in the ICLR'15 paper "Object Detectors Emerge in Deep Scene CNNs". So basically I need to get top K images with the highest activation for the given unit from a dataset. I tried to do that by comparing feature maps but it doesn't give good results. My question is, if we give an image to the model, how can we get the activation of each unit ? Thank you again for your help.
@alikasim7658
@alikasim7658 3 жыл бұрын
I am facing the same issue in my work, in fact, i am trying to extract feature maps from each conv layer and do some computations on them before feeding them to the next conv layer ( this must done on fly during training not after model trained). I fed up searching how to do that extraction coz KerasTensor (which is the type of conv layer) is not changeable to numpy array. @DigitalSreeni, could you please help in this issue
@rezadarooei248
@rezadarooei248 3 жыл бұрын
is it possible to use this in unet?
@DigitalSreeni
@DigitalSreeni 3 жыл бұрын
Yes.
@wesuli
@wesuli 4 жыл бұрын
Thank you for the helpful video ..
@brunospfc8511
@brunospfc8511 2 жыл бұрын
05/07/22 journey continues
@callmebiz
@callmebiz 2 жыл бұрын
what IDE is this?
@DigitalSreeni
@DigitalSreeni 2 жыл бұрын
Spyder. Comes with Anaconda.
@shashireddy7371
@shashireddy7371 4 жыл бұрын
Thank you Sreeni.
@DigitalSreeni
@DigitalSreeni 4 жыл бұрын
You are welcome.
@salilmarathponmadom7255
@salilmarathponmadom7255 2 жыл бұрын
Nice Tutorial
@coemgeincraobhach236
@coemgeincraobhach236 3 жыл бұрын
Thanks so much for this!
@junaidiqbal5018
@junaidiqbal5018 3 жыл бұрын
Nicely done
@DigitalSreeni
@DigitalSreeni 3 жыл бұрын
Thank you! Cheers!
@geogob
@geogob 4 жыл бұрын
thank you for your videos
@DigitalSreeni
@DigitalSreeni 4 жыл бұрын
My pleasure!
@duoyizhang4665
@duoyizhang4665 3 жыл бұрын
Thank you so much!
@DigitalSreeni
@DigitalSreeni 3 жыл бұрын
You're welcome!
@omkarpatil9234
@omkarpatil9234 2 жыл бұрын
Sir , if you think about it, your voice is just like Jordan Peterson
@ManishKumar-bb5ql
@ManishKumar-bb5ql 4 жыл бұрын
u r a jam👌
@82shadowheart
@82shadowheart 3 жыл бұрын
Thanks! )
@caiyu538
@caiyu538 3 жыл бұрын
thumb it up
@qusayhamad7243
@qusayhamad7243 2 жыл бұрын
Thank you Sir it was too helpful and clear
@qusayhamad7243
@qusayhamad7243 2 жыл бұрын
Thank you Sir it was too helpful and clear
@qusayhamad7243
@qusayhamad7243 2 жыл бұрын
Thank you Sir it was too helpful and clear
@qusayhamad7243
@qusayhamad7243 2 жыл бұрын
Thank you Sir it was too helpful and clear
154 - Understanding the training and validation loss curves
27:47
DigitalSreeni
Рет қаралды 111 М.
So Cute 🥰 who is better?
00:15
dednahype
Рет қаралды 19 МЛН
Sigma Kid Mistake #funny #sigma
00:17
CRAZY GREAPA
Рет қаралды 30 МЛН
小丑教训坏蛋 #小丑 #天使 #shorts
00:49
好人小丑
Рет қаралды 54 МЛН
But what is a convolution?
23:01
3Blue1Brown
Рет қаралды 2,8 МЛН
'How neural networks learn' - Part I: Feature Visualization
15:00
Arxiv Insights
Рет қаралды 106 М.
158 - Convolutional filters + Random Forest for image classification.
27:14
Convolutional Neural Network from Scratch | Mathematics & Python Code
33:23
The Independent Code
Рет қаралды 196 М.
142 - Multilabel classification using Keras
19:23
DigitalSreeni
Рет қаралды 47 М.
How I animate 3Blue1Brown | A Manim demo with Ben Sparks
53:41
3Blue1Brown
Рет қаралды 1,3 МЛН
Visualizing activations with forward hooks (PyTorch)
18:58
mildlyoverfitted
Рет қаралды 14 М.
So Cute 🥰 who is better?
00:15
dednahype
Рет қаралды 19 МЛН