# Visualize weights of convolutional layer built locally?

**URL:** <https://community.wolfram.com/t/visualize-weights-of-convolutional-layer-built-locally/11945>\
**Category:** Questions\
**Tags:** graphics-and-visualization, machine-learning, neural-networks\
**Created:** [February 11, 2018, 8:38am UTC](https://community.wolfram.com/t/visualize-weights-of-convolutional-layer-built-locally/11945 "2018-02-11T08:38:37Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ashish01012013](https://avatars.discourse-cdn.com/v4/letter/a/b38774/32.png) [@ashish01012013](https://community.wolfram.com/u/ashish01012013)\
**Post date:** [February 11, 2018, 8:38am UTC](https://community.wolfram.com/t/visualize-weights-of-convolutional-layer-built-locally/11945/1 "2018-02-11T08:38:37Z")

</div>

Hi,  
First of all i apologize if this question has already been answered but i am unable to find a solution hence i am asking.  
I have been trying to build a CNN to classify the MNIST dataset. I have imported the data from local folder and have trained the network.  
My problem is that i would like to visualize the weights but have been receiving an error. I have tried various sources but have failed to find out what the problem is.  
Please kindly help me to find out what is wrong with my code.

```
conv1 = ConvolutionLayer[20, {5, 5}, "PaddingSize" -> 0, 
   "Stride" -> 1 ];
conv2 = ConvolutionLayer[50, {5, 5}, "PaddingSize" -> 0, 
   "Stride" -> 1];
block1 = {conv1, Ramp, PoolingLayer[2, 2], conv2, Ramp, 
   PoolingLayer[2, 2], FlattenLayer[], 500, Ramp, class, 
   SoftmaxLayer[]};

leNet = NetChain[block1, 
  "Output" -> 
   NetDecoder[{"Class", {"0", "1", "2", "3", "4", "5", "6", "7", "8", 
      "9"}}], "Input" -> NetEncoder[{"Image", {28, 28}, "Grayscale"}]]

trainedNet = 
 NetTrain[leNet, trainingData, ValidationSet -> testingData, 
  MaxTrainingRounds -> maxTrainingRounds, BatchSize -> batchSize]

weights = NetExtract[leNet, {"conv1", "Weights"}];
Dimensions[weights]

out = { }

ImageAdjust[Image[#, Interleaving -> False]] & /@ weights

out = Missing["NotPresent", {"conv1", "Weights"}]

```

---

<div class="post-metadata">

**Author:** ![okazakikotaro](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/okazakikotaro/32/14323_2.png) [@okazakikotaro](https://community.wolfram.com/u/okazakikotaro)\
**Post date:** [February 12, 2018, 11:25am UTC](https://community.wolfram.com/t/visualize-weights-of-convolutional-layer-built-locally/11945/2 "2018-02-12T11:25:08Z")

</div>

Ashish, please change some codes.

```
leNet = NetChain[block1, 
  "Output" -> NetDecoder[{"Class", {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}}], 
  "Input" -> NetEncoder[{"Image", {28, 28}, "Grayscale"}]]

weights = NetExtract[trainedNet, {1, "Weights"}];

```

You can visualize weights of conv1(Layer 1).

```
ImageAdjust[Image[#, Interleaving -> False]] & /@ weights

```

![w.jpg](https://global.discourse-cdn.com/wolfram/optimized/3X/a/f/af1d10cd78a488daac1236b6b7bfaeda27af5e7b_2_932x35.jpeg)

---

<div class="post-metadata">

**Author:** ![ashish01012013](https://avatars.discourse-cdn.com/v4/letter/a/b38774/32.png) [@ashish01012013](https://community.wolfram.com/u/ashish01012013)\
**Post date:** [February 12, 2018, 4:30pm UTC](https://community.wolfram.com/t/visualize-weights-of-convolutional-layer-built-locally/11945/3 "2018-02-12T16:30:39Z")

</div>

I thank you so much for giving me the solution and such a quick response.
