-
Notifications
You must be signed in to change notification settings - Fork 479
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unable to load saved model #107
Comments
Hello. Have you solved the error? |
I have the same exact issue with loading any of the COVID-Net CXR models. |
I'm facing the same problem... |
I have managed to load the model as a graph using the code provided in inference.py (import_meta_graph function). |
Oh, can you just send the code of inference.py. I'm actually a beginner, so I'm not sure whether the file arguments for the parser I'm inputting is correct... I actually want a .tflite format model. |
The only thing I really changed was the way I pass the arguments, I created a dictionary containing the info about the model (default info that can be seen in the inference.py script was used). args = { 'name': 'COVIDNet-CXR4-A', 'weightspath': '/path_to_model_directory/COVIDNet-CXR4-A', 'metaname': 'model.meta', 'ckptname': 'model-18540', 'in_tensorname': 'input_1:0', 'out_tensorname': 'norm_dense_1/Softmax:0', 'input_size': 480, 'top_percent': 0.08 } Then it is basically the same as follows: new_graph = tf.Graph() with tf.Session(graph=new_graph) as sess: tf.get_default_graph() saver = tf.train.import_meta_graph(os.path.join(args['weightspath'], args['metaname'])) saver.restore(sess, os.path.join(args['weightspath'], args['ckptname'])) covid_net = tf.get_default_graph() mapping = {0: 'negative', 1: 'positive'} image_tensor = graph.get_tensor_by_name(args['in_tensorname']) pred_tensor = graph.get_tensor_by_name(args['out_tensorname']) x = process_image_file(img_path, args['top_percent'], args['input_size']) x = x.astype('float32') / 255.0 pred = sess.run(pred_tensor, feed_dict={image_tensor: np.expand_dims(x, axis=0)}) # Combining pneumonia and covid predictions into single pneumonia prediction. pred_pneumonia = np.array([pred[0][0], np.max([pred[0][1], pred[0][2]])]) pred_pneumonia = pred_pneumonia / np.sum(pred_pneumonia) print('Prediction: {}'.format(mapping[pred_pneumonia.argmax()])) print('Confidence') print('Negative (Normal): {:.3f}, Positive (Pneumonia): {:.3f}'.format(pred_pneumonia[0], pred_pneumonia[1])) Mind you, this code is prepared to fit my specific needs, so it is a binary prediction of COVID-19 negative or positive samples. |
I want to try it with the COVIDNet-CXR-LargeThis is the Inference.py file:
But I'm getting this error:WARNING:tensorflow:From /Users/kapil/.local/lib/python3.8/site-packages/tensorflow/python/compat/v2_compat.py:96: disable_resource_variables (from tensorflow.python.ops.variable_scope) is deprecated and will be removed in a future version. Please help me!!! |
Looking at the history of the inference file, it seems the pred_tensor (out_tensor in arguments) should be called "dense_3/Softmax:0" for the CXR-Large model. Check this file out, compare it to your case: https://github.com/lindawangg/COVID-Net/blob/46b4b00ab049f02e02e81829c5fd2cafb5caad2c/inference.py |
Solved that issue, but I don't know why but I'm getting this now: Why am I getting this now?? Also, how do I actually do the inference part by comparing it with an example image?? I know I'm asking too much, but please help me!! |
Well, the inference script uses the process_image_file function to preprocess the images (I think there's some resizing and random augmentation going on). You need to import the function correctly so that the code you posted above can work. Make sure the file 'data' contains that function definition and you could try something like I don't really know what you mean by your second question. You give the input file path to the script in the variable img_path (you can see it is the argument of the preprocessing function) and the script will print the probabilities for each class and tell you the highest one. You should know which class the image really belonged to based on the data labels. I don't know how to convert the model to TF light, I am also a beginner and haven't encountered this, sorry. |
got it working! Thanks a lot! |
You're welcome :) Yeah the way @hzhaoc tried with Keras was also not working for me. I'm not familiar with TF/Keras enough to resolve that issue unfortunately. |
I am getting the same error so I would like to know if anyone of you has created the Keras based save file of the mode. If so then can you please share that file with me. |
Unable to load saved model
Unable to load saved model.
Steps to Reproduce
Expected behavior
output": tensorflow.python.keras.engine.sequential.Sequential
Actual behavior
ValueError: Node 'gradients/post_bn/cond/FusedBatchNorm_grad/FusedBatchNormGrad' has an _output_shapes attribute inconsistent with the GraphDef for output #3: Dimension 0 in both shapes must be equal, but are 0 and 2048. Shapes are [0] and [2048].
Environment
tensorflow 2.3.1
The text was updated successfully, but these errors were encountered: