You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Google Colab昨日正常运行的Keras ResNet50代码今日报错求解

问题描述

完全相同的深度学习程序,昨日在Google Colab平台运行全部正常,今日重新打开运行时出现不明报错,该程序为本人编写的第一个深度学习程序。

报错截图

Google Colab平台运行报错界面

对应实现代码
#Step3: test_img_path: Location of the image we want the model to predict
  test_img = image.load_img(test_img_path,target_size=(224,224))
  #Step4: Deep learning models expect a batch of images represented by array
  # At this stage we will have a processed image of size 224x224x3. 
  # Convert it to a batch of images denoted by nx224x224x3 where n denotes total images
  # In this case, n=1
  test_img_array = image.img_to_array(test_img)
  # Convert the array to a batch
  test_img_batch = np.expand_dims(test_img_array,axis=0)  
  #Step5: At the data level, an original image data is stored in the in terms of the pixels. 
  # Now, normalizing the image
  nor_testimg = preprocess_input(test_img_batch)  
  #Step6: Import the model and input our test image
  # Model here means, it is already trained by someone else and I don't have to do it again
  # Moreover, they made their hardwork or trained model freely available to every on on the keras, we just download it
  model = tf.keras.applications.resnet50.ResNet50()  
  #Step7: Lets see how and what the model would predict
  predict_testimg = model.predict(nor_testimg)
  # Decode the predictions
  print(decode_predictions(predict_testimg,top=3)[0]) 
初步排查结果
  • 已定位今日运行的报错触发点为tf.keras.applications.resnet50.ResNet50()代码行,该语句在昨日运行时无任何异常
  • 若去掉该行末尾的括号,将代码写为tf.keras.applications.resnet50.ResNet50,当前行可正常执行,但会在下一行代码运行时触发新的报错
  • 现咨询该问题的产生原因,以及对应的可行解决方法

内容的提问来源于stack exchange,提问作者Mainland

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.29 07:16:02