基于tensorflow 高光谱图像分类代码
时间: 2023-07-27 07:07:34 浏览: 142
以下是一个基于TensorFlow的高光谱图像分类代码示例:
```python
import tensorflow as tf
import numpy as np
# 加载数据
data = np.load('data.npy')
labels = np.load('labels.npy')
# 划分训练集和测试集
train_data = data[:800]
train_labels = labels[:800]
test_data = data[800:]
test_labels = labels[800:]
# 构建模型
model = tf.keras.models.Sequential([
tf.keras.layers.Flatten(input_shape=(data.shape[1], data.shape[2])),
tf.keras.layers.Dense(128, activation='relu'),
tf.keras.layers.Dense(10)
])
# 编译模型
model.compile(optimizer='adam',
loss=tf.keras.losses.SparseCategoricalCrossentropy(from_logits=True),
metrics=['accuracy'])
# 训练模型
model.fit(train_data, train_labels, epochs=10)
# 评估模型
test_loss, test_acc = model.evaluate(test_data, test_labels, verbose=2)
print('\nTest accuracy:', test_acc)
# 预测新数据
predictions = model.predict(test_data)
```
这是一个简单的全连接神经网络模型,输入为高光谱图像,输出为分类结果。在训练数据上训练完成后,可以使用测试数据进行模型评估,并使用模型对新数据进行分类预测。
阅读全文
相关推荐
![.zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![-](https://img-home.csdnimg.cn/images/20241231045053.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![-](https://img-home.csdnimg.cn/images/20241231045053.png)
![-](https://img-home.csdnimg.cn/images/20241231044930.png)
![-](https://img-home.csdnimg.cn/images/20241231045053.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![-](https://img-home.csdnimg.cn/images/20241231045053.png)
![-](https://img-home.csdnimg.cn/images/20241231045053.png)
![-](https://img-home.csdnimg.cn/images/20241231045053.png)