lucid icon indicating copy to clipboard operation
lucid copied to clipboard

Importing custom model - "Model.save" method does not exists

Open Shulk7 opened this issue 5 years ago • 7 comments

Hello, I was trying to import a custom model to use with lucid, and using the wiki page "https://github.com/tensorflow/lucid/wiki/Importing-Models-into-Lucid" . I installed Lucid v0.3.8 using pip. When I do this code:

from lucid.modelzoo.vision_models import Model
Model.save()

I get this error :

AttributeError: type object 'Model' has no attribute 'save'

How come the method "save" does not exist ? Is the tutorial outdated?

Edit : The last PIP version of Lucid is 0.3.8 and is from Decembre 2018. Since the above tutorial says "As of 2019, the recommended way to import models for visualization is using Lucid's Model.save()" I installed Lucid directly from the github repository to have an updated version. Now "Model.save()" works. I think it would be better to precise in the tutorial that the procedure only works for 0.3.9

Shulk7 avatar Apr 21 '20 17:04 Shulk7

Hello, I have the same problem. Install lucid 0.3.9 from the master branch did work for some cases, like the Keras built-in models (VGG, Inception) and InceptionV1 pb file from "gs://modelzoo/vision/other_models/InceptionV1.pb" . However, I still can't get my own model work with lucid. It seems like the versions of tensorflow and keras matters, can you please share me your solution in detail ? @Shulk7 @colah

zzusunjs avatar Nov 08 '20 12:11 zzusunjs

Hello, I advise you to look at my fork from lucid (https://github.com/Shulk97/lucid) I created on the branch "fixing_notebook_and_adding_jupyter" an example script to import a Keras model in Lucid 0.3.9 available here https://github.com/Shulk97/lucid/blob/fixing_notebook_and_adding_jupyter/lucid/recipes/keras_model_import_example.py. It was tested with Tensorflow 1.15 and Lucid 0.3.9. The example show how to import MobileNet from tf.keras.applications but you can just change it for Inception and change the parameters "image_shape" and "image_value_range" if needed. Let me know if it works for you

Shulk97 avatar Nov 11 '20 17:11 Shulk97

Hello, I advise you to look at my fork from lucid (https://github.com/Shulk97/lucid) I created on the branch "fixing_notebook_and_adding_jupyter" an example script to import a Keras model in Lucid 0.3.9 available here https://github.com/Shulk97/lucid/blob/fixing_notebook_and_adding_jupyter/lucid/recipes/keras_model_import_example.py. It was tested with Tensorflow 1.15 and Lucid 0.3.9. The example show how to import MobileNet from tf.keras.applications but you can just change it for Inception and change the parameters "image_shape" and "image_value_range" if needed. Let me know if it works for you

Good Job and Thank you. 😀 I got my problem fixed by using the Keras function API to build the model instead of model.add. It was tested with Tensorflow1.14.0 and Lucid 0.3.9 and Keras 2.2.5.

zzusunjs avatar Nov 12 '20 02:11 zzusunjs

Hello, I am trying to convert and save my YOLOV3 Model - .h5 file to .pb file. I am facing the same issue. I tried https://github.com/Shulk97/lucid/blob/fixing_notebook_and_adding_jupyter/lucid/recipes/keras_model_import_example.py this but no result.

from lucid.modelzoo.vision_models import Model
from keras_yolo3.yolo import YOLO
import keras

with tf.Graph().as_default() as graph, tf.Session() as sess:
    yolo=YOLO(**{"model_path": model_path,
                "anchors_path": anchors_path,
                "classes_path": classes_path,
                "score" : score,
                "gpu_num" : gpu_num,
                "model_image_size" : (416, 416),
                }
            )

    model=yolo.yolo_model
    Model.save(
      "some_directory/saved_model_1.pb",
      image_shape=[416, 416, 3],
      input_name='InputLayer',
      output_names=['LeakyReLU'],
      
    )

Error: AttributeError: type object 'Model' has no attribute 'save' I have Trained using this repo https://github.com/AntonMu/TrainYourOwnYOLO Tensorflow1.15.0 and Lucid 0.3.8 and Keras 2.3.1.

Karthik-U-94 avatar Nov 24 '20 13:11 Karthik-U-94

Hello, my tutorial script only works with Lucid 0.3.9 that you can get with pip install git+https://github.com/tensorflow/lucid.git. That being said, I'm not sure YOLO will work on Lucid because it's an image detection network not a classification network. I guess it could work with the classification backbone of YOLO.

Shulk97 avatar Nov 24 '20 13:11 Shulk97

I am getting a very low detection accuracy so I am trying to analyze this network.., I tried many libraries but most of all support Classification network. @Shulk97 Thank you for the quick response.

Karthik-U-94 avatar Nov 24 '20 13:11 Karthik-U-94

Hi @Shulk97 I was getting this same error and with the code of your branch fixing_notebook_and_adding_jupyter I did not get it anymore. However, I get a different error: AssertionError: softmax/Softmax is not in graph

I checked the model layer names and saw that the name of the last layer was 'act_softmax', so I replaced it by this but I continued having the same kind of error.

This also happens with my custom models, I have set the names of my output layers but the error says those are not in the graph.

Any ideas?

PS: I am using

  • keras '2.3.1' (I have also tried with '2.2.5')
  • tf '1.14.0'
  • lucid version from your repo (0.3.9)

mcamila777 avatar Dec 02 '20 23:12 mcamila777