FailedPreconditionError Keras

时间:2018-10-28 03:06:32

标签: python neural-network keras deep-learning

我正在尝试将遮罩应用于所捕获的屏幕部分。 screen = grab_screen(region=(0,40,800,640))。然后,我应用包含在另一个文件中的函数。 screen = road_lines_image(screen)(这就是我导入from linedetect import road_lines_image的方式)。在另一个文件中,我具有以下功能。

def road_lines_image(imageIn):
    #crop to 720x1280, img[y: y + h, x: x + w], 300:940
    image = imageIn[230:950, 0:1280]
    image = imresize(image, (640, 1280, 3))

    # Get image ready for feeding into model
    small_img = imresize(image, (80, 160, 3))
    small_img = np.array(small_img)

    small_img = small_img[None,:,:,:]

    # Make prediction with neural network (un-normalize value by multiplying by 255)
    prediction = model.predict(small_img)[0] * 255

(函数更长,但最后一行是我遇到错误的地方。从主文件调用函数后,我出现了错误

FailedPreconditionError (see above for traceback): Attempting to use uninitialized value Final/kernel
         [[{{node Final/kernel/read}} = Identity[T=DT_FLOAT, _device="/job:localhost/replica:0/task:0/device:CPU:0"](Final/kernel)]]

我尝试从road_lines_image所在的文件中运行以下代码

img = cv2.imread("road-traffic-car-981035.jpg")
img  = road_lines_image(img)
cv2.imshow('image',img)
cv2.waitKey(0)

此代码工作完美,我得到了期望的输出。从主文件运行时遇到问题。

1 个答案:

答案 0 :(得分:0)

解决了!我在函数之外声明了模型。我在里面添加了它,现在可以正常使用了!