Skip to content
This repository has been archived by the owner on Apr 10, 2024. It is now read-only.

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

Open
Shulk7 opened this issue Apr 21, 2020 · 7 comments
Open

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

Shulk7 opened this issue Apr 21, 2020 · 7 comments

Comments

@Shulk7
Copy link

Shulk7 commented Apr 21, 2020

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

@zzusunjs
Copy link

zzusunjs commented Nov 8, 2020

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

@Shulk97
Copy link

Shulk97 commented Nov 11, 2020

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

@zzusunjs
Copy link

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.

@Karthik-U-94
Copy link

Karthik-U-94 commented Nov 24, 2020

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.

@Shulk97
Copy link

Shulk97 commented Nov 24, 2020

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.

@Karthik-U-94
Copy link

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.

@mcamila777
Copy link

mcamila777 commented Dec 2, 2020

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)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants