metinovadilet
commited on
Commit
•
076d8d4
1
Parent(s):
b79b433
First version of model
Browse filestrained on small part of the land , west of Bishkek
- meer/Meer.h5 +3 -0
- meer/mean_values_summary.csv +193 -0
- meer/model_creation.py +96 -0
meer/Meer.h5
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:f8b1fa84aa028104253b6aee5f2e166c986fc79c88c75e694aec2bfb463e3846
|
3 |
+
size 75896
|
meer/mean_values_summary.csv
ADDED
@@ -0,0 +1,193 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
Year,Month,Type,Mean_Value
|
2 |
+
2014,01,NDVI,0.03637381
|
3 |
+
2014,02,NDVI,-7.648369e-05
|
4 |
+
2014,03,NDVI,-0.0102609545
|
5 |
+
2014,04,NDVI,0.21833025
|
6 |
+
2014,05,NDVI,0.4029976
|
7 |
+
2014,06,NDVI,0.39842525
|
8 |
+
2014,07,NDVI,0.33484557
|
9 |
+
2014,08,NDVI,0.28024414
|
10 |
+
2014,09,NDVI,0.2678122
|
11 |
+
2014,10,NDVI,0.22297126
|
12 |
+
2014,11,NDVI,0.20621522
|
13 |
+
2014,12,NDVI,0.018370138
|
14 |
+
2014,01,NDWI,-0.07105442
|
15 |
+
2014,02,NDWI,-0.026667532
|
16 |
+
2014,03,NDWI,-0.0108920885
|
17 |
+
2014,04,NDWI,-0.25271535
|
18 |
+
2014,05,NDWI,-0.3947968
|
19 |
+
2014,06,NDWI,-0.41528398
|
20 |
+
2014,07,NDWI,-0.38426134
|
21 |
+
2014,08,NDWI,-0.34330943
|
22 |
+
2014,09,NDWI,-0.33599624
|
23 |
+
2014,10,NDWI,-0.26565516
|
24 |
+
2014,11,NDWI,-0.19662789
|
25 |
+
2014,12,NDWI,-0.0534919
|
26 |
+
2015,01,NDVI,0.015824856
|
27 |
+
2015,02,NDVI,0.01410047
|
28 |
+
2015,03,NDVI,0.21014738
|
29 |
+
2015,04,NDVI,0.38612852
|
30 |
+
2015,05,NDVI,0.52105993
|
31 |
+
2015,06,NDVI,0.37829387
|
32 |
+
2015,07,NDVI,0.31312978
|
33 |
+
2015,08,NDVI,0.31475097
|
34 |
+
2015,09,NDVI,0.3148233
|
35 |
+
2015,10,NDVI,0.28065836
|
36 |
+
2015,11,NDVI,0.20766294
|
37 |
+
2015,12,NDVI,0.023235604
|
38 |
+
2015,01,NDWI,-0.04799539
|
39 |
+
2015,02,NDWI,-0.043714006
|
40 |
+
2015,03,NDWI,-0.2247919
|
41 |
+
2015,04,NDWI,-0.3677456
|
42 |
+
2015,05,NDWI,-0.47811177
|
43 |
+
2015,06,NDWI,-0.40399328
|
44 |
+
2015,07,NDWI,-0.36933282
|
45 |
+
2015,08,NDWI,-0.3726222
|
46 |
+
2015,09,NDWI,-0.33410805
|
47 |
+
2015,10,NDWI,-0.30120784
|
48 |
+
2015,11,NDWI,-0.2045634
|
49 |
+
2015,12,NDWI,-0.058232486
|
50 |
+
2016,01,NDVI,0.031631526
|
51 |
+
2016,02,NDVI,0.108674325
|
52 |
+
2016,03,NDVI,0.2726109
|
53 |
+
2016,04,NDVI,0.45824805
|
54 |
+
2016,05,NDVI,0.60704374
|
55 |
+
2016,06,NDVI,0.49255392
|
56 |
+
2016,07,NDVI,0.44270635
|
57 |
+
2016,08,NDVI,0.41391832
|
58 |
+
2016,09,NDVI,0.3552221
|
59 |
+
2016,10,NDVI,0.31184065
|
60 |
+
2016,11,NDVI,0.14771272
|
61 |
+
2016,12,NDVI,
|
62 |
+
2016,01,NDWI,-0.06354797
|
63 |
+
2016,02,NDWI,-0.1311203
|
64 |
+
2016,03,NDWI,-0.27396092
|
65 |
+
2016,04,NDWI,-0.412583
|
66 |
+
2016,05,NDWI,-0.52879846
|
67 |
+
2016,06,NDWI,-0.46289545
|
68 |
+
2016,07,NDWI,-0.43069345
|
69 |
+
2016,08,NDWI,-0.41207507
|
70 |
+
2016,09,NDWI,-0.37520212
|
71 |
+
2016,10,NDWI,-0.32266992
|
72 |
+
2016,11,NDWI,-0.16108795
|
73 |
+
2016,12,NDWI,
|
74 |
+
2017,01,NDVI,0.028299352
|
75 |
+
2017,02,NDVI,-0.0004300331
|
76 |
+
2017,03,NDVI,0.15977669
|
77 |
+
2017,04,NDVI,0.34166
|
78 |
+
2017,05,NDVI,0.5606122
|
79 |
+
2017,06,NDVI,0.5247286
|
80 |
+
2017,07,NDVI,0.3560093
|
81 |
+
2017,08,NDVI,0.3450487
|
82 |
+
2017,09,NDVI,0.3213928
|
83 |
+
2017,10,NDVI,0.26438868
|
84 |
+
2017,11,NDVI,0.16974592
|
85 |
+
2017,12,NDVI,
|
86 |
+
2017,01,NDWI,-0.06207667
|
87 |
+
2017,02,NDWI,-0.025918996
|
88 |
+
2017,03,NDWI,-0.18314826
|
89 |
+
2017,04,NDWI,-0.33923197
|
90 |
+
2017,05,NDWI,-0.497302
|
91 |
+
2017,06,NDWI,-0.49217677
|
92 |
+
2017,07,NDWI,-0.3974867
|
93 |
+
2017,08,NDWI,-0.39300305
|
94 |
+
2017,09,NDWI,-0.37551898
|
95 |
+
2017,10,NDWI,-0.3116423
|
96 |
+
2017,11,NDWI,-0.18042384
|
97 |
+
2017,12,NDWI,
|
98 |
+
2018,01,NDVI,0.043647703
|
99 |
+
2018,02,NDVI,0.022244323
|
100 |
+
2018,03,NDVI,0.1468368
|
101 |
+
2018,04,NDVI,0.38621
|
102 |
+
2018,05,NDVI,0.553758
|
103 |
+
2018,06,NDVI,0.4577191
|
104 |
+
2018,07,NDVI,0.371388
|
105 |
+
2018,08,NDVI,0.32523742
|
106 |
+
2018,09,NDVI,0.28276566
|
107 |
+
2018,10,NDVI,0.24991055
|
108 |
+
2018,11,NDVI,0.057450306
|
109 |
+
2018,12,NDVI,0.10182946
|
110 |
+
2018,01,NDWI,-0.08074473
|
111 |
+
2018,02,NDWI,-0.049971007
|
112 |
+
2018,03,NDWI,-0.16181277
|
113 |
+
2018,04,NDWI,-0.36271462
|
114 |
+
2018,05,NDWI,-0.50257903
|
115 |
+
2018,06,NDWI,-0.45652497
|
116 |
+
2018,07,NDWI,-0.3978019
|
117 |
+
2018,08,NDWI,-0.3673624
|
118 |
+
2018,09,NDWI,-0.33057702
|
119 |
+
2018,10,NDWI,-0.31096348
|
120 |
+
2018,11,NDWI,-0.083236896
|
121 |
+
2018,12,NDWI,-0.11330218
|
122 |
+
2019,01,NDVI,0.12812804
|
123 |
+
2019,02,NDVI,0.07167658
|
124 |
+
2019,03,NDVI,0.16254286
|
125 |
+
2019,04,NDVI,0.3810431
|
126 |
+
2019,05,NDVI,0.5881861
|
127 |
+
2019,06,NDVI,0.41373178
|
128 |
+
2019,07,NDVI,0.33502045
|
129 |
+
2019,08,NDVI,0.30443558
|
130 |
+
2019,09,NDVI,0.27136824
|
131 |
+
2019,10,NDVI,0.2249414
|
132 |
+
2019,11,NDVI,0.17058644
|
133 |
+
2019,12,NDVI,0.015977545
|
134 |
+
2019,01,NDWI,-0.13369952
|
135 |
+
2019,02,NDWI,-0.09915775
|
136 |
+
2019,03,NDWI,-0.18232904
|
137 |
+
2019,04,NDWI,-0.36428666
|
138 |
+
2019,05,NDWI,-0.51711845
|
139 |
+
2019,06,NDWI,-0.4318895
|
140 |
+
2019,07,NDWI,-0.38278067
|
141 |
+
2019,08,NDWI,-0.36510453
|
142 |
+
2019,09,NDWI,-0.32055837
|
143 |
+
2019,10,NDWI,-0.26932168
|
144 |
+
2019,11,NDWI,-0.20094076
|
145 |
+
2019,12,NDWI,-0.045890413
|
146 |
+
2020,01,NDVI,0.02600833
|
147 |
+
2020,02,NDVI,0.10948946
|
148 |
+
2020,03,NDVI,0.159752
|
149 |
+
2020,04,NDVI,0.38456792
|
150 |
+
2020,05,NDVI,0.5776242
|
151 |
+
2020,06,NDVI,0.45694545
|
152 |
+
2020,07,NDVI,0.35098165
|
153 |
+
2020,08,NDVI,0.30593276
|
154 |
+
2020,09,NDVI,0.27941108
|
155 |
+
2020,10,NDVI,0.21813856
|
156 |
+
2020,11,NDVI,0.043937486
|
157 |
+
2020,12,NDVI,0.047411535
|
158 |
+
2020,01,NDWI,-0.0595021
|
159 |
+
2020,02,NDWI,-0.13303731
|
160 |
+
2020,03,NDWI,-0.18740809
|
161 |
+
2020,04,NDWI,-0.36957166
|
162 |
+
2020,05,NDWI,-0.51577485
|
163 |
+
2020,06,NDWI,-0.46002954
|
164 |
+
2020,07,NDWI,-0.40317768
|
165 |
+
2020,08,NDWI,-0.34992763
|
166 |
+
2020,09,NDWI,-0.31799856
|
167 |
+
2020,10,NDWI,-0.2716179
|
168 |
+
2020,11,NDWI,-0.067942545
|
169 |
+
2020,12,NDWI,-0.08969609
|
170 |
+
2021,01,NDVI,0.031039532
|
171 |
+
2021,02,NDVI,0.12767474
|
172 |
+
2021,03,NDVI,0.17752129
|
173 |
+
2021,04,NDVI,0.3315446
|
174 |
+
2021,05,NDVI,0.4536556
|
175 |
+
2021,06,NDVI,0.3575767
|
176 |
+
2021,07,NDVI,0.30110878
|
177 |
+
2021,08,NDVI,0.28985253
|
178 |
+
2021,09,NDVI,0.26736796
|
179 |
+
2021,10,NDVI,0.22649986
|
180 |
+
2021,11,NDVI,0.06251545
|
181 |
+
2021,12,NDVI,0.13564047
|
182 |
+
2021,01,NDWI,-0.069737405
|
183 |
+
2021,02,NDWI,-0.14461634
|
184 |
+
2021,03,NDWI,-0.21508418
|
185 |
+
2021,04,NDWI,-0.33986288
|
186 |
+
2021,05,NDWI,-0.44316238
|
187 |
+
2021,06,NDWI,-0.39590663
|
188 |
+
2021,07,NDWI,-0.35498592
|
189 |
+
2021,08,NDWI,-0.34644762
|
190 |
+
2021,09,NDWI,-0.3233553
|
191 |
+
2021,10,NDWI,-0.27977043
|
192 |
+
2021,11,NDWI,-0.099415764
|
193 |
+
2021,12,NDWI,-0.15367758
|
meer/model_creation.py
ADDED
@@ -0,0 +1,96 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# -*- coding: utf-8 -*-
|
2 |
+
"""
|
3 |
+
Created on Sun Mar 24 14:50:30 2024
|
4 |
+
|
5 |
+
@author: Metinov Adilet
|
6 |
+
"""
|
7 |
+
|
8 |
+
import rasterio
|
9 |
+
import os
|
10 |
+
import numpy as np
|
11 |
+
import pandas as pd
|
12 |
+
from sklearn.model_selection import train_test_split
|
13 |
+
from tensorflow.keras.models import Sequential
|
14 |
+
from tensorflow.keras.layers import Dense
|
15 |
+
from tensorflow.keras.optimizers import Adam
|
16 |
+
|
17 |
+
def calculate_mean_value(src, crop_window):
|
18 |
+
left, top, width, height = crop_window
|
19 |
+
image_data = src.read(1, window=rasterio.windows.Window(left, top, width, height))
|
20 |
+
return np.mean(image_data)
|
21 |
+
|
22 |
+
# Инициализируем список для сохранения результатов
|
23 |
+
results = []
|
24 |
+
|
25 |
+
# Путь к директории с изображениями
|
26 |
+
image_directory = 'C:\\Users\\Administrator\\Desktop\\Data\\'
|
27 |
+
months = ['01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12']
|
28 |
+
crop_window = (0, 0, 1200, 1200)
|
29 |
+
|
30 |
+
# Цикл по годам
|
31 |
+
for year in range(2014, 2022): # 2022, потому что range не включает конечное значение
|
32 |
+
# Цикл для NDVI и NDWI
|
33 |
+
for prefix in ['NDVI', 'NDWI']:
|
34 |
+
for month in months:
|
35 |
+
image_path = os.path.join(image_directory, f'{prefix}_Image_{year}_{month}.tif')
|
36 |
+
if os.path.exists(image_path):
|
37 |
+
with rasterio.open(image_path) as src:
|
38 |
+
mean_value = calculate_mean_value(src, crop_window)
|
39 |
+
results.append({'Year': year, 'Month': month, 'Type': prefix, 'Mean_Value': mean_value})
|
40 |
+
else:
|
41 |
+
print(f'Image for {year}_{month} not found.')
|
42 |
+
|
43 |
+
# Создаем DataFrame из списка результатов
|
44 |
+
results_df = pd.DataFrame(results)
|
45 |
+
|
46 |
+
# Сохраняем результаты в CSV файл
|
47 |
+
output_path = os.path.join(image_directory, 'mean_values_summary.csv')
|
48 |
+
results_df.to_csv(output_path, index=False)
|
49 |
+
|
50 |
+
print(f'Results saved to {output_path}')
|
51 |
+
|
52 |
+
# Загружаем данные
|
53 |
+
data_df = pd.read_csv(output_path)
|
54 |
+
|
55 |
+
# Проверяем на наличие nan в столбце 'Mean_Value' и заменяем на соответствующие значения
|
56 |
+
for i, row in data_df.iterrows():
|
57 |
+
if pd.isnull(row['Mean_Value']):
|
58 |
+
if row['Type'] == 'NDVI':
|
59 |
+
data_df.at[i, 'Mean_Value'] = 0.2
|
60 |
+
elif row['Type'] == 'NDWI':
|
61 |
+
data_df.at[i, 'Mean_Value'] = -0.2
|
62 |
+
|
63 |
+
# Преобразуем 'Type' с помощью one-hot encoding
|
64 |
+
type_dummies = pd.get_dummies(data_df['Type'], prefix='Type')
|
65 |
+
data_df = pd.concat([data_df.drop('Type', axis=1), type_dummies], axis=1)
|
66 |
+
|
67 |
+
# Преобразование всех данных в float32
|
68 |
+
data_df['Year'] = data_df['Year'].astype('float32')
|
69 |
+
data_df['Month'] = data_df['Month'].astype('float32')
|
70 |
+
for column in type_dummies.columns:
|
71 |
+
data_df[column] = data_df[column].astype('float32')
|
72 |
+
|
73 |
+
# Создаем признаки (X) и цель (y), убедимся, что все данные в нужном формате
|
74 |
+
X = data_df.drop('Mean_Value', axis=1).astype('float32')
|
75 |
+
y = data_df['Mean_Value'].astype('float32')
|
76 |
+
|
77 |
+
# Разделяем данные на обучающую и тестовую выборки
|
78 |
+
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
|
79 |
+
# Определение модели
|
80 |
+
model = Sequential([
|
81 |
+
Dense(64, activation='relu', input_shape=(X_train.shape[1],)),
|
82 |
+
Dense(64, activation='relu'),
|
83 |
+
Dense(1)
|
84 |
+
])
|
85 |
+
|
86 |
+
# Компиляция модели
|
87 |
+
model.compile(optimizer=Adam(learning_rate=0.001), loss='mean_squared_error')
|
88 |
+
|
89 |
+
# Обучение модели
|
90 |
+
history = model.fit(X_train, y_train, validation_split=0.2, epochs=100, batch_size=32)
|
91 |
+
|
92 |
+
# Оценка модели на тестовых данных
|
93 |
+
loss = model.evaluate(X_test, y_test)
|
94 |
+
print(f'Test loss: {loss}')
|
95 |
+
# Сохранение обученной модели
|
96 |
+
model.save('C:\\Users\\Administrator\\Desktop\\Data\\Model\\Meer.h5')
|