日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

使用cnn预测房价_使用CNN的人和马预测

發(fā)布時(shí)間:2023/12/15 编程问答 21 豆豆
生活随笔 收集整理的這篇文章主要介紹了 使用cnn预测房价_使用CNN的人和马预测 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

使用cnn預(yù)測房價(jià)

There are many transfer learning methods to solve classification problems with respect to the accuracy, i.e 1.VGG (e.g. VGG16 or VGG19) 2.GoogLeNet (e.g. InceptionV3).3.Residual Network (e.g. ResNet50).These are some pre-trained models, but here we are going to build an end to end model as per the convolutional neural networks architecture.

有很多轉(zhuǎn)移學(xué)習(xí)方法可以解決關(guān)于準(zhǔn)確性的分類問題,例如1.VGG(例如VGG16或VGG19)2.GoogLeNet(例如InceptionV3).3.Residual Network(例如ResNet50)。這些是一些預(yù)先訓(xùn)練的模型,但是在這里,我們將根據(jù)卷積神經(jīng)網(wǎng)絡(luò)架構(gòu)來構(gòu)建端到端模型。

卷積神經(jīng)網(wǎng)絡(luò) (Convolutional Neural Network)

There are many definitions to describe CNN but in simple terms, convolutional refers to the mathematical combination of two functions to produce a third function. It merges two sets of information. in the case of a CNN is used to analyze visual imaginary. They are also known as shift invariant or space invariant artificial neural networks, based on their shared-weights architecture and translation invariance characteristics.

描述CNN的定義很多,但簡單來說,卷積是指兩個(gè)函數(shù)的數(shù)學(xué)組合以產(chǎn)生第三個(gè)函數(shù)。 它合并了兩組信息。 在使用CNN的情況下,可以分析視覺虛像。 基于它們的共享權(quán)重架構(gòu)和平移不變性特征,它們也被稱為位移不變或空間不變的人工神經(jīng)網(wǎng)絡(luò)。

Source資源

CNN中的圖層 (Layers in CNN)

There are three layers in CNN, convolutional layer, pooling layer, and fully connected layer. Each of these layers has different parameters that can be optimized and performs a different task on the input data.

CNN分為三層:卷積 ,池化和完全連接 。 這些層中的每個(gè)都有可以優(yōu)化的不同參數(shù),并且對輸入數(shù)據(jù)執(zhí)行不同的任務(wù)。

Source資源

池化層 (Pooling Layer)

The pooling layer is a building block on CNN. its function progressively reduces the spatial size of the presentation to reduce the number of parameters and computation in network. The pooling layer operates on each feature map independently. max-pooling is the most common approach used in the convolutional neural networks.

池化層是CNN的基礎(chǔ)。 它的功能逐漸減小了演示文稿的空間大小,從而減少了網(wǎng)絡(luò)中的參數(shù)和計(jì)算量。 池化層在每個(gè)要素地圖上獨(dú)立運(yùn)行。 最大池化是卷積神經(jīng)網(wǎng)絡(luò)中最常用的方法。

數(shù)據(jù)集 (Dataset)

We have data for training:

我們有用于培訓(xùn)的數(shù)據(jù):

500 horse images and 527 humans (male & Female) images

500張馬圖像和527位人類(男性和女性)圖像

For Validation:

驗(yàn)證:

122 Horse Images and 123 Human(male & Female) images

122張馬圖像和123張人類(男性和女性)圖像

Dataset link

數(shù)據(jù)集鏈接

實(shí)作 (Implementation)

Importing necessary libraries and packages.

導(dǎo)入必要的庫和包。

import kerasfrom keras.preprocessing.image import ImageDataGeneratorimport matplotlib.pyplot as plt

資料載入 (Data Load)

train_data = "train/"
validation_data = "validation/"

Here we have train and validation datasets, we will use train data for training and validation data to prevent overfitting problem. also here we have a small size of the dataset as we before building the CNN model the data should have huge images to make the most accurate model. so we will generate more images using image augmentation.

這里有訓(xùn)練和驗(yàn)證數(shù)據(jù)集,我們將訓(xùn)練數(shù)據(jù)用于訓(xùn)練和驗(yàn)證數(shù)據(jù)以防止過擬合問題。 同樣,在這里,我們的數(shù)據(jù)集很小,因?yàn)樵跇?gòu)建CNN模型之前,數(shù)據(jù)應(yīng)該具有巨大的圖像以構(gòu)成最準(zhǔn)確的模型。 因此我們將使用圖像增強(qiáng)生成更多圖像。

數(shù)據(jù)預(yù)處理 (Data Preprocessing)

#For tarining
train_data_gen = ImageDataGenerator(rescale=1./255,
rotation_range=40,
width_shift_range=0.2,
height_shift_range=0.2,
shear_range=0.2,
zoom_range=0.2,
horizontal_flip=True,
fill_mode='nearest')

Generating more training data for model training using image data generator parameters like rotation and width, height, zoom range.

使用圖像數(shù)據(jù)生成器參數(shù)(例如旋轉(zhuǎn)和寬度,高度,縮放范圍)為模型訓(xùn)練生成更多訓(xùn)練數(shù)據(jù)。

train_data1 = train_data_gen.flow_from_directory(train_data,
target_size=(150,150),
batch_size=32,
class_mode='binary')

Let’s Check the image classes

讓我們檢查一下圖像類

train_data1.class_indices

The classes are divided as {‘horses’: 0, ‘humans’: 1}.

這些類別分為{'horses':0,'humans':1}。

Now Generating for validation.

現(xiàn)在生成以進(jìn)行驗(yàn)證。

validation_data_gen = ImageDataGenerator(rescale=1./255)
validation_data1 = validation_data_gen.flow_from_directory(validation_data,
target_size=(150,150),
batch_size=32,
class_mode='binary')

Now plotting the generated images.

現(xiàn)在繪制生成的圖像。

def plotImages(images_arr):
fig, axes = plt.subplots(1, 5, figsize=(20, 20))
axes = axes.flatten()
for img, ax in zip(images_arr, axes):
ax.imshow(img)
plt.tight_layout()
plt.show()

Let’s plots some training image datasets.

讓我們繪制一些訓(xùn)練圖像數(shù)據(jù)集。

images = [train_data1[0][0][0] for i in range(5)]
plotImages(images)Augmented Image增強(qiáng)圖像

建立CNN (Building CNN)

We are using Keras here so it makes code much simpler form because it uses TensorFlow API. so let’s start to build a model step by step.

我們在這里使用Keras,因?yàn)樗褂肨ensorFlow API,所以它使代碼的形式更簡單。 因此,讓我們開始逐步構(gòu)建模型。

cnn_model = keras.models.Sequential([
keras.layers.Conv2D(filters=32, kernel_size=3, input_shape=[150,150,3]),
keras.layers.MaxPooling2D(pool_size=(2,3)),
keras.layers.Conv2D(filters=64, kernel_size=3),
keras.layers.MaxPooling2D(pool_size=(2,2)),
keras.layers.Conv2D(filters=128, kernel_size=3),
keras.layers.MaxPooling2D(pool_size=(2,2)),
keras.layers.Conv2D(filters=256, kernel_size=3),
keras.layers.MaxPooling2D(pool_size=(2,2)),

keras.layers.Dropout(0.5),
keras.layers.Flatten(), #after this we will go for neural network building
keras.layers.Dense(units=128, activation='relu'), #inputlayers
keras.layers.Dropout(0.1),
keras.layers.Dense(units=256, activation='relu'), #Hidden layer
keras.layers.Dropout(0.25),
keras.layers.Dense(units=2, activation='softmax') #output layer with 2 neurons

])

Basically we took 128 for input and 256 neurons for hidden, and we used relu and softmax activation functions, with respect to classes we used softmax activation function. Now let’s compile the model.

基本上,我們使用128個(gè)輸入作為輸入,使用256個(gè)神經(jīng)元進(jìn)行隱藏,并使用relu和softmax激活函數(shù),就使用softmax激活函數(shù)的類而言。 現(xiàn)在讓我們編譯模型。

from keras.optimizers import Adamfrom keras.callbacks import ModelCheckpoint

Let’s set the optimizer and loss function now.

現(xiàn)在設(shè)置優(yōu)化器和損失函數(shù)。

cnn_model.compile(optimizer=Adam(lr=0.0001), loss='sparse_categorical_crossentropy', metrics=['accuracy'])

Before going to build a model we can set a path to save our model, so in my case, I have set my local systems path.

在構(gòu)建模型之前,我們可以設(shè)置保存模型的路徑,因此,就我而言,我已經(jīng)設(shè)置了本地系統(tǒng)路徑。

model_path='human_horse_predict.h5'checkpoint = ModelCheckpoint(model_path, monitor='val_accuracy', verbose=1, save_best_only=True, mode='max')
callbacks_list = [checkpoint]

模型火車 (Model Train)

history = cnn_model.fit(train_data1,
epochs=100,
verbose=1,
validation_data=validation_data1,
callbacks=callbacks_list)

I have trained this model by using Cuda and it took less time for training, better you can train using Google COLAB.

我已經(jīng)使用Cuda訓(xùn)練了該模型,并且花了更少的時(shí)間進(jìn)行訓(xùn)練,更好的是可以使用Google COLAB進(jìn)行訓(xùn)練。

Now the model is trained, let’s see the summary of the model.

現(xiàn)在已經(jīng)對模型進(jìn)行了訓(xùn)練,讓我們看看模型的摘要。

#Summarize history for accuracy
plt.plot(history.history['accuracy'])
plt.plot(history.history['val_accuracy'])
plt.title('Model Loss')
plt.ylabel('accuracy')
plt.xlabel('epoch')
plt.legend(['train', 'test'], loc='upper left')
plt.show()

Let’s look at our model accuracy on train and test data.

讓我們看看我們在訓(xùn)練和測試數(shù)據(jù)上的模型準(zhǔn)確性。

Plot情節(jié)

You can see how our model is overfitted as per epoch. Let’s test the model.

您可以看到我們的模型在每個(gè)時(shí)期都是過擬合的。 讓我們測試一下模型。

模型測試 (Model Test)

model1 = keras.models.load_model(model_path)

Give the saved model path.

給出保存的模型路徑。

Let’s take some human and horse images and assing in some variables.

讓我們拍攝一些人和馬的圖像,并評估一些變量。

##Horse images
h1 = 'train/horses/horse01-1.png'
h2 = 'train/horses/horse01-2.png'
h3 = 'train/horses/horse01-5.png'#human images
hu1 = 'train/humans/human01-02.png'
hu2 = 'train/humans/human01-05.png'
hu3 = 'train/humans/human01-08.png

Creating one function which will prepress our image in an array format.

創(chuàng)建一個(gè)將以數(shù)組格式預(yù)印圖像的功能。

import numpy as npfrom keras.preprocessing import image

Defining function.

定義功能。

def pred_human_horse(model, horse_or_human):
test_image = image.load_img(horse_or_human, target_size = (155,155))
test_image = image.img_to_array(test_image)/255
test_image = np.expand_dims(test_image, axis=0)

result = model.predict(test_image).round(3)

pred = np.argmax(result)

if pred==0:
print("Horse")
else:
print("Human")

預(yù)測 (Prediction)

For using three images we are going to predict.

對于使用三個(gè)圖像,我們將進(jìn)行預(yù)測。

for horse_or_human in [h1,h2,h3]:
pred_human_horse(model1, horse_or_human)Horse
Horse
Horse

So, we got a good prediction here.

因此,我們在這里得到了很好的預(yù)測。

Hope you like this article, we can improve this model for using hyperparameter tuning and you can also try the pre-trained models likeVGG (e.g. VGG16 or VGG19).

希望您喜歡本文,我們可以改進(jìn)此模型以使用超參數(shù)調(diào)整,還可以嘗試使用預(yù)訓(xùn)練的模型,例如VGG(例如VGG16或VGG19)。

IPython notebook.

IPython 筆記本 。

Github Link for all machine learning and Deep Learning Resources, and you can also see my machine learning deployments using Flask API.

Github 鏈接提供了所有機(jī)器學(xué)習(xí)和深度學(xué)習(xí)資源,您還可以使用Flask API查看我的機(jī)器學(xué)習(xí)部署。

翻譯自: https://towardsdatascience.com/human-and-horse-prediction-using-cnn-563309f988ff

使用cnn預(yù)測房價(jià)

總結(jié)

以上是生活随笔為你收集整理的使用cnn预测房价_使用CNN的人和马预测的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 日韩免费福利 | 成人性生交大片免费看中文 | 日本在线小视频 | www.av网 | 美女扒开内裤让男人捅 | 巨胸大乳www视频免费观看 | 日韩va视频 | 一本一道久久 | 国产激情自拍视频 | 91黄视频在线观看 | 日韩啊啊啊 | 日日摸日日碰夜夜爽av | 欧美女人交配视频 | 老司机深夜视频 | 久久久久一区 | 欧美日韩黄色片 | 动漫美女露胸网站 | 最新av女优| 一区二区av电影 | 男女视频网站 | 亚洲精品久久夜色撩人男男小说 | 95精品视频 | 爆操91| 91偷拍精品一区二区三区 | 精品丰满人妻无套内射 | 51调教丨国产调教视频 | 国产高清免费 | 国产91沙发系列 | 国产日韩一区二区三区 | 极品销魂美女一区二区三区 | 国产超碰自拍 | 免费三级黄 | 日韩精品成人无码专区免费 | 麻豆免费在线观看视频 | 国产在线观看中文字幕 | 欧美日韩中文字幕一区二区三区 | 丝袜综合网 | 国产无套粉嫩白浆内谢 | 一区二区三区麻豆 | 好吊妞视频在线观看 | 91免费观看入口 | 日韩免费视频一区二区视频在线观看 | av每日更新 | 久久亚洲成人 | 精品人妻一区二区三区蜜桃视频 | 日韩在线播放一区 | 人人妻人人爽欧美成人一区 | 91视频网址入口 | 亚洲+小说+欧美+激情+另类 | 韩日产理伦片在线观看 | 91精品国产成人www | 美女视频在线免费观看 | 日韩av一级片 | 国内精品卡一卡二卡三 | 中文字幕在线看高清电影 | 丁香六月激情综合 | av影片在线观看 | 无码人妻精品一区二区三区在线 | 精品黑人一区二区三区观看时间 | 中文一级片 | 色射视频| 国家队动漫免费观看在线观看晨光 | 日本午夜免费 | 日本精品一区视频 | 成人a级大片 | 奇米影视狠狠干 | 欧美a视频在线观看 | 亚洲精品久久久久久无码色欲四季 | 91 高清 在线 制服 偷拍 | 日本三级小视频 | 91a视频| 91色在线播放 | 五月天婷婷综合网 | 日本www高清视频 | 伊人啪啪网 | 黄色片免费视频 | 黄色av小说在线观看 | 激情午夜天| 日本成人在线视频网站 | 欧美日韩日本国产 | 国产91丝袜在线观看 | 男人的网站在线观看 | avtt在线观看 | 资源av | 中文字幕一区二区人妻痴汉电车 | 欧美日韩亚洲不卡 | 欧美久久久久久久久久久久 | 国产精品美女自拍视频 | 日韩精品免费一区二区三区竹菊 | 丰满人妻一区二区三区精品高清 | 免费在线观看高清影视网站 | 日本a∨视频 | 青青伊人影院 | 久久久久久久久久久久久国产 | 久久久久久电影 | 无码免费一区二区三区 | 97小视频| 天堂中文在线资源 | 91精品久久香蕉国产线看观看 |