- Practical Convolutional Neural Networks
- Mohit Sewak Md. Rezaul Karim Pradeep Pujari
- 209字
- 2021-06-24 18:58:53
Code for visualizing an image
Let's take a look at how an image can be visualized with the following code:
#import all required lib
import matplotlib.pyplot as plt
%matplotlib inline
import numpy as np
from skimage.io import imread
from skimage.transform import resize
# Load a color image in grayscale
image = imread('sample_digit.png',as_grey=True)
image = resize(image,(28,28),mode='reflect')
print('This image is: ',type(image),
'with dimensions:', image.shape)
plt.imshow(image,cmap='gray')
We obtain the following image as a result:

def visualize_input(img, ax):
ax.imshow(img, cmap='gray')
width, height = img.shape
thresh = img.max()/2.5
for x in range(width):
for y in range(height):
ax.annotate(str(round(img[x][y],2)), xy=(y,x),
horizontalalignment='center',
verticalalignment='center',
color='white' if img[x][y]<thresh else 'black')
fig = plt.figure(figsize = (12,12))
ax = fig.add_subplot(111)
visualize_input(image, ax)
The following result is obtained:

In the previous chapter, we used an MLP-based approach to recognize images. There are two issues with that approach:
- It increases the number of parameters
- It only accepts vectors as input, that is, flattening a matrix to a vector
This means we must find a new way to process images, in which 2D information is not completely lost. CNNs address this issue. Furthermore, CNNs accept matrices as input. Convolutional layers preserve spatial structures. First, we define a convolution window, also called a filter, or kernel; then slide this over the image.
推薦閱讀
- Access 2016數(shù)據(jù)庫教程(微課版·第2版)
- 從零開始學(xué)Hadoop大數(shù)據(jù)分析(視頻教學(xué)版)
- 文本數(shù)據(jù)挖掘:基于R語言
- 大數(shù)據(jù):規(guī)劃、實(shí)施、運(yùn)維
- 基于OPAC日志的高校圖書館用戶信息需求與檢索行為研究
- INSTANT Android Fragmentation Management How-to
- 區(qū)塊鏈+:落地場景與應(yīng)用實(shí)戰(zhàn)
- 機(jī)器學(xué)習(xí):實(shí)用案例解析
- Google Cloud Platform for Architects
- 標(biāo)簽類目體系:面向業(yè)務(wù)的數(shù)據(jù)資產(chǎn)設(shè)計方法論
- 數(shù)據(jù)庫技術(shù)與應(yīng)用:SQL Server 2008
- SQL Server 數(shù)據(jù)庫教程(2008版)
- 數(shù)據(jù)庫應(yīng)用技術(shù)
- Kubernetes云原生數(shù)據(jù)管理
- 讓Oracle跑得更快:Oracle 10g性能分析與優(yōu)化思路