import cv2
import skimage
import numpy as np
import keras
import os
import matplotlib.pyplot as plt
import keras.backend as K
import tensorflow as tf
from PIL import Image
from keras.models import Sequential,Model,load_model,model_from_json
from keras.layers import Input,Add,Conv2D,Conv3D,Concatenate,ConvLSTM2D,BatchNormalization,LeakyReLU,MaxPool2D,UpSampling2D,TimeDistributed
from keras.optimizers import Adam,SGD
from keras.callbacks import ModelCheckpoint,EarlyStopping
from utilsp import RadarData
os.environ['CUDA_VISIBLE_DEVICES'] = '1'
IMAGE_PATH = 'radar/'
#IMAGE_PATH = '/content/drive/MyDrive/nowcasting/train/'
INPUT_SEQUENCE = np.array([])
NEXT_SEQUENCE = np.array([])
smooth = 1e-9
class Config(object):
WIDTH = 64
HEIGHT = 64
def ssim(x,y,max_val=255.0):
return tf.image.ssim(x,y,max_val)
def psnr(x,y,max_val=255.0):
return tf.image.psnr(x,y,max_val)
#recall
def POD(x,y):
y_pos = K.clip(x,0,1)
y_pred_pos = K.clip(y,0,1)
y_pred_neg = 1 - y_pred_pos
tp = K.sum(y_pos * y_pred_pos)
fn = K.sum(y_pos * y_pred_neg)
return (tp+smooth)/(tp+fn+smooth)
def FAR(x,y):
y_pred_pos = K.clip(y,0,1)
y_pos = K.clip(x,0,1)
y_neg = 1 - y_pos
tp = K.sum(y_pos * y_pred_pos)
fp = K.sum(y_neg * y_pred_pos)
return (fp)/(tp+fp+smooth)
def Net():
contentInput = Input(shape=(None,Config.WIDTH,Config.HEIGHT,1),name='content_input')
x = ConvLSTM2D(64,(3,3),padding='same',dropout=0.2,return_sequences=True,kernel_initializer='he_normal',name='layer1')(contentInput)
x = BatchNormalization()(x)
x = ConvLSTM2D(64,(3,3),padding='same',dropout=0.2,return_sequences=True,kernel_initializer='he_normal',name='layer2')(x)
x = BatchNormalization()(x)
x = ConvLSTM2D(64,(3,3),padding='same',dropout=0.2,return_sequences=True,kernel_initializer='he_normal',name='layer3')(x)
x = BatchNormalization()(x)
x = ConvLSTM2D(64,(3,3),padding='same',dropout=0.2,return_sequences=True,kernel_initializer='he_normal',name='layer4')(x)
x = BatchNormalization()(x)
x = ConvLSTM2D(64,(3,3),padding='same',dropout=0.2,return_sequences=True,kernel_initializer='he_normal',name='layer5')(x)
x = BatchNormalization()(x)
predictions = Conv3D(filters=1,kernel_size=(3,3,3),activation='linear',padding='same',data_format='channels_last')(x)
model = Model(inputs=contentInput,outputs=predictions)
return model
def train(*args):
model,epochs,train_gen = args
metrics = ['accuracy',ssim,psnr,POD,FAR]
optim = Adam(lr=1e-3,beta_1=0.9,beta_2=0.999,amsgrad=False)
model.compile(loss='logcosh',optimizer=optim,metrics=metrics)
checkpoint = ModelCheckpoint(filepath='weights-2-{epoch:03d}-{loss:.2f}.h5',monitor='loss',save_best_only=False,save_weights_only=True)
checkpoint.set_model(model)
model.fit_generator(train_gen,epochs=epochs,callbacks=[checkpoint])
if __name__ == '__main__':
model = Net()
model.summary()
tf.keras.utils.plot_model(model,to_file='model.png',show_shapes=True,show_layer_names=True)
images = sorted(os.listdir(IMAGE_PATH))[:500]
#print(images)
"""
for image in images:
vis(os.path.join('train/',image))
"""
#gen = RadarData(images=images)
#train(model,80,gen)
"""
x,y = next(iter(gen))
print(x.shape,y.shape)
for i in range(2):
for j in range(16):
img_x = x[i,j,:,:,:]
img_y = y[i,j,:,:,:]
cv2.imshow('x',img_x)
cv2.imshow('y',img_y)
cv2.waitKey(0)
"""
没有合适的资源?快使用搜索试试~ 我知道了~
nowcasting.zip
共4个文件
py:3个
h5:1个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
5星 · 超过95%的资源 35 下载量 23 浏览量
2021-02-08
11:22:39
上传
评论 5
收藏 4.73MB ZIP 举报
温馨提示
基于convLSTM的短临预报模型,付费下载后提供长期技术支持,确保模型稳定运行
资源推荐
资源详情
资源评论
收起资源包目录
upload.zip (4个子文件)
upload
infer.py 3KB
weights-071-0.13.h5 5.13MB
nowcasting.py 3KB
utilsp.py 3KB
共 4 条
- 1
nobrody
- 粉丝: 302
- 资源: 9
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
- 3
- 4
- 5
- 6
前往页