Google Colab昨日正常运行的Keras ResNet50代码今日报错求解
问题描述
完全相同的深度学习程序,昨日在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
相关产品推荐
相关产品推荐

