Python
 Computer >> コンピューター >  >> プログラミング >> Python

畳み込みの概要-Pythonを使用


この記事では、Python3.xでの畳み込みについて学習します。またはそれ以前。この記事はニューラルネットワークと特徴抽出に分類されます。

推奨 −Jupyterノートブック

前提条件 − Numpyがインストールされ、Matplotlibがインストールされました

インストール

>>> pip install numpy
>>>pip install matplotlib

畳み込み

畳み込みは、画像上にスライディングウィンドウのようなカーネル/座標コンテナと呼ばれる小さなコンテナを適用することにより、画像から特徴を抽出するために画像に対して実行できる操作の一種です。畳み込み座標コンテナの値に応じて、画像から特定のパターン/特徴を取得できます。ここでは、適切な座標コンテナを使用した画像内の水平および垂直の端点の検出について学習します。

それでは、実際の実装を見てみましょう。

import numpy as np
from matplotlib import pyplot
# initializing the images
img1 = np.array([np.array([100, 100]), np.array([80, 80])])
img2 = np.array([np.array([100, 100]), np.array([50, 0])])
img3 = np.array([np.array([100, 50]), np.array([100, 0])])
coordinates_horizontal = np.array([np.array([3, 3]), np.array([-3, -3])])
print(coordinates_horizontal, 'is a coordinates for detecting horizontal end points')
coordinates_vertical = np.array([np.array([3, -3]), np.array([3, - 3])])
print(coordinates_vertical, 'is a coordinates for detecting vertical end points')
#his will be an elemental multiplication followed by addition
def apply_coordinates(img, coordinates):
   return np.sum(np.multiply(img, coordinates))
# Visualizing img1
pyplot.imshow(img1)
pyplot.axis('off')
pyplot.title('sample 1')
pyplot.show()
# Checking for horizontal and vertical features in image1
print('Horizontal end points features score:',
apply_coordinates(img1, coordinates_horizontal))
print('Vertical end points features score:',
apply_coordinates(img1,coordinates_vertical))
# Visualizing img2
pyplot.imshow(img2)
pyplot.axis('off')
pyplot.title('sample 2')
pyplot.show()
# Checking for horizontal and vertical features in image2
print('Horizontal end points features score:',
apply_coordinates(img2, coordinates_horizontal))
print('Vertical end points features score:',
apply_coordinates(img2, coordinates_vertical))
# Visualizing img3
pyplot.imshow(img3)
pyplot.axis('off')
pyplot.title('sample 3')
pyplot.show()
# Checking for horizontal and vertical features in image1
print('Horizontal end points features score:',
apply_coordinates(img3,coordinates_horizontal))
print('Vertical end points features score:',
apply_coordinates(img3,coordinates_vertical))

出力

畳み込みの概要-Pythonを使用

結論

この記事では、Python3.xを使用した畳み込みの概要について学習しました。またはそれ以前とその実装。


  1. JavaScriptの配列slice()

    JavaScript配列slice()メソッドは、選択したアイテムの新しい配列をより大きな配列で返します。元のアレイは変更されません。 以下は、配列slice()メソッドのコードです- 例 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /&

  2. C#の次元配列?

    C#では多次元配列が可能です。 intの2次元配列をとして宣言します。 int [ , , ] a; 多次元配列の最も単純な形式は、2次元配列です。 2次元配列は、1次元配列のリストです。 以下は、3行4列の2次元配列です。 ここで、C#で多次元配列を操作する例を見てみましょう。 例 using System; namespace ArrayApplication {    class MyArray {       static void Main(string[] args) {       &nb