NotImplementedError:无法将符号张量(up_sampling2d_5_target_1:0)转换为numpy数组

时间:2020-02-10 13:54:46

标签: python keras unity3d-unet

import keras.backend as K
from keras.optimizers import Adam
from keras.losses import binary_crossentropy

## intersection over union
def IoU(y_true, y_pred, eps=1e-6):
    print(type(y_true))
    print(y_true)
    if np.max(y_true) == 0.0:
        return IoU(1-y_true, 1-y_pred) ## empty image; calc IoU of zeros
    intersection = K.sum(y_true * y_pred, axis=[1,2,3])
    union = K.sum(y_true, axis=[1,2,3]) + K.sum(y_pred, axis=[1,2,3]) - intersection
    return -K.mean( (intersection + eps) / (union + eps), axis=0)  




def fit():
        seg_model.compile(optimizer=Adam(1e-3, decay=1e-6), loss=IoU, metrics=['binary_accuracy'])

    step_count = min(MAX_TRAIN_STEPS, train_df.shape[0]//BATCH_SIZE)
    aug_gen = create_aug_gen(make_image_gen(train_df))
    loss_history = [seg_model.fit_generator(aug_gen,
                                 steps_per_epoch=step_count,
                                 epochs=MAX_TRAIN_EPOCHS,
                                 validation_data=(valid_x, valid_y),
                                 callbacks=callbacks_list,
                                workers=1 # the generator is not very thread safe
                                           )]
    return loss_history

while True:
    loss_history = fit()
    if np.min([mh.history['val_loss'] for mh in loss_history]) < -0.2:
        break

我从这段代码中得到了这个错误

--------------------------------------------------- ---------------------------- NotImplementedError Traceback(最近的调用 最后) 14 15,而True: ---> 16 loss_history = fit() 17如果np.min([mh.history ['val_loss'] for mh in loss_history])<-0.2: 18休息

in fit() 1 def fit(): ----> 2 seg_model.compile(optimizer = Adam(1e-3,衰减= 1e-6),损失= IoU,指标= ['binary_accuracy']) 3 4步数=最小值(MAX_TRAIN_STEPS,train_df.shape [0] // BATCH_SIZE) 5 aug_gen = create_aug_gen(make_image_gen(train_df))

〜/ venv / lib / python3.7 / site-packages / keras / backend / tensorflow_backend.py 在symbolic_fn_wrapper(* args,** kwargs)中 73如果_SYMBOLIC_SCOPE.value: 74与get_graph()。as_default(): ---> 75 return func(* args,** kwargs) 其他76个: 77 return func(* args,** kwargs)

〜/ venv / lib / python3.7 / site-packages / keras / engine / training.py在 编译(自我,优化程序,损失,指标,loss_weights, sample_weight_mode,weighted_metrics,target_tensors,** kwargs) 第227节 228#层损失。 -> 229 self.total_loss = self._prepare_total_loss(掩码) 230 231#用于训练,测试和预测的功能

〜/ venv / lib / python3.7 / site-packages / keras / engine / training.py在 _prepare_total_loss(自我,面具) 690 第691章 -> 692 y_true,y_pred,sample_weight = sample_weight) 693 第694章没钱了

〜/ venv / lib / python3.7 / site-packages / keras / losses.py,致电(自我, y_true,y_pred,sample_weight) 69 scope_name ='lambda'如果self.name ==''else self.name 70与K.name_scope(scope_name): ---> 71损失= self.call(y_true,y_pred) 72 return loss_utils.compute_weighted_loss( 73个损失,sample_weight,reduction = self.reduction)

〜/ venv / lib / python3.7 / site-packages / keras / losses.py在通话中(self, y_true,y_pred) 每个样品130损失值。 131“”“ -> 132返回self.fn(y_true,y_pred,** self._fn_kwargs) 133 134 def get_config():

IoU中的

(y_true,y_pred,eps) 5 ##联合路口 6 def IoU(y_true,y_pred,eps = 1e-6): ----> 7如果np.max(y_true)== 0.0: 8 return IoU(1-y_true,1-y_pred)##空图片;计算IoU零 9个交点= K.sum(y_true * y_pred,axis = [1,2,3])

<< strong> array_function internals> in amax(* args,** kwargs)

〜/ venv / lib / python3.7 / site-packages / numpy / core / fromnumeric.py在 amax(a,轴,出,keepdims,初始位置)2619“”“ 2620
return _wrapreduction(a,np.maximum,'max',axis,None,out, -> 2621 keepdims = keepdims,initial = initial,where = where)2622 2623

〜/ venv / lib / python3.7 / site-packages / numpy / core / fromnumeric.py在 _wrapreduction(obj,ufunc,method,axis,dtype,out,** kwargs) 88折返幅度减少(轴=轴,输出=出,** passkwargs) 89 ---> 90 return ufunc.reduce(obj,axis,dtype,out,** passkwargs) 91 92

〜/ venv / lib / python3.7 / site-packages / tensorflow_core / python / framework / ops.py 在数组中(自己) 734 def 数组(个体): 735提高了NotImplementedError(“无法将符号张量({})转换为小数” -> 736“数组。”。format(self.name)) 737 738分 len (自己):

NotImplementedError:无法转换符号张量 (up_sampling2d_5_target_1:0)转换为numpy数组。

0 个答案:

没有答案