机器学习————花的种类识别
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
accuracy =history.history['acc']
loss = history.history['loss']
val_loss = history.history['val_loss']
val_accuracy = history.history['val_acc']
plt.figure(figsize=(17, 7))
plt.subplot(2, 2, 1)
plt.plot(range(30), accuracy,'bo', label='Training Accuracy')
plt.plot(range(30), val_accuracy, label='Validation Accuracy')
plt.legend(loc='lower right')
plt.title('Accuracy : Training vs. Validation ')
plt.subplot(2, 2, 2)
plt.plot(range(30), loss,'bo' ,label='Training Loss')
plt.plot(range(30), val_loss, label='Validation Loss')
plt.title('Loss : Training vs. Validation ')
plt.legend(loc='upper right')
plt.show()
warnings.filterwarnings("ignore")
model=load_model('flower/flowermodel.h5')
img_path = "flower/test/flower1.jpg"
img = image_utils.load_img(img_path, target_size=(150,150))
img_tensor = image_utils.img_to_array(img)
img_tensor = np.expand_dims(img_tensor, axis=0)
img_tensor /= 255.
print(img_tensor.shape)
plt.imshow(img_tensor[0])
layer_outputs = [layer.output for layer in model.layers[:8]]
activation_model = models.Model(inputs=model.input, outputs=layer_outputs)
activations = activation_model.predict(img_tensor)
first_layer_activation = activations[0]
plt.matshow(first_layer_activation[0,:,:,1], cmap="viridis")
layer_names = []
for layer in model.layers[:4]:
layer_names.append(layer.name)
images_pre_row = 16
for layer_name, layer_activation in zip(layer_names, activations):
n_features = layer_activation.shape[-1]
size = layer_activation.shape[1]
n_col = n_features // images_pre_row
display_grid = np.zeros((size * n_col, images_pre_row * size))
for col in range(n_col):
for row in range(images_pre_row):
channel_image = layer_activation[0, :, :, col * images_pre_row + row]
channel_image -= channel_image.mean()
channel_image /= channel_image.std()
channel_image *= 64
channel_image += 128
channel_image = np.clip(channel_image, 0, 255).astype("uint8")
display_grid[col * size:(col + 1) * size, row * size:(row + 1) * size] = channel_image
scale = 1. / size
plt.figure(figsize=(scale * display_grid.shape[1], scale * display_grid.shape[0]))
plt.title(layer_name)
plt.grid(False)
plt.imshow(display_grid, aspect="auto", cmap="viridis")
import os
import matplotlib.pyplot as plt
from PIL import Image
import os.path
def convertjpg(jpgfile, outdir, width=150, height=150):
img = Image.open(jpgfile)
try:
new_img = img.resize((width, height), Image.BILINEAR)
new_img.save(os.path.join(outdir, os.path.basename(jpgfile)))
except Exception as e:
print(e)
jpgfile1 = 'flower/test/flower1.jpg'
jpgfile2 = 'flower/test/flower2.jpg'
jpgfile3 = 'flower/test/flower3.jpg'
jpgfile4 = 'flower/test/flower4.jpg'
jpgfile5 = 'flower/test/flower5.jpg'
convertjpg(jpgfile1, "flower/newtest/")
convertjpg(jpgfile2, "flower/newtest/")
convertjpg(jpgfile3, "flower/newtest/")
convertjpg(jpgfile4, "flower/newtest/")
convertjpg(jpgfile5, "flower/newtest/")
img_scale = plt.imread('flower/newtest/flower2.jpg')
plt.imshow(img_scale)
img='flower/newtest/flower1.jpg'
img_scale = plt.imread(img)
plt.imshow(img_scale)
plt.show()
img_scale = img_scale.reshape(1,150,150,3).astype('float32')
img_scale = img_scale/255
result = model.predict(img_scale)
print(result)
dict={'0':'菊花','1':'蒲公英','2':'玫瑰','3':'向日葵','4':'郁金香'}
for i in range(5):
if result[0][i]>0.5:
print( '这是:'+ dict[str(i)])
相关知识
【机器学习】花卉识别01
深度学习机器学习卷积神经网络的花卉识别花种类识别
机器如何识别花的种类
一种基于机器学习的花朵种类识别方法与流程
机器学习在植物病害识别研究中的应用
基于深度学习的花卉图像种类识别
基于机器学习的花卉识别
深度学习在植物种类及病害识别领域的研究
机器学习在农业领域的应用现状
深度学习花卉识别:Python数据集解析
网址: 机器学习————花的种类识别 https://www.huajiangbk.com/newsview648271.html
上一篇: 基于神经网络的食用玫瑰花图像识别 |
下一篇: 花分类数据集(玫瑰花等) |
推荐分享

- 1君子兰什么品种最名贵 十大名 4012
- 2世界上最名贵的10种兰花图片 3364
- 3花圈挽联怎么写? 3286
- 4迷信说家里不能放假花 家里摆 1878
- 5香山红叶什么时候红 1493
- 6花的意思,花的解释,花的拼音 1210
- 7教师节送什么花最合适 1167
- 8勿忘我花图片 1103
- 9橄榄枝的象征意义 1093
- 10洛阳的市花 1039