mikeyEcology / MLWIC2

Classify camera trap images using machine learning with R Shiny Apps
36 stars 17 forks source link

Using the estimated models outside of MLWIC2 #15

Open vmielecnrs opened 4 years ago

vmielecnrs commented 4 years ago

Hi,

Could it be possible to use the estimated models (I mean, the model weights, for instance in architecture ResNet-18) outside of MLWIC2, for those of us who prefer Python for instance, or who have their own codes already running?

I would like, for instance, to reuse your estimated models in my codes implemented in Keras. Do you think it could be possible?

If this require some code development, I can participate in the effort.

mikeyEcology commented 4 years ago

The weights are stored in the helper files folder, which you can download from Step 3 in the readme. If you open the species_model folder, you can see the snapshots. These models were trained in tensorflow, so you should be able to load them in Keras.

vmielecnrs commented 4 years ago

Thanks for the answer. Not easy to do, by the way.

Is your Python code only working with TensorFlow version 1?

pretrained_loader = tf.train.Saver(var_list= self.exclude())
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: module 'tensorflow._api.v2.train' has no attribute 'Saver'
mikeyEcology commented 4 years ago

Yes. There are tons of version issues with Tensorflow. You'll need tensorflow 1.14 and python 3.7.

vmielecnrs commented 4 years ago

It turns out that I get many problems with the "eager mode":

pretrained_loader = tf.train.Saver(tf.get_collection(tf.GraphKeys.GLOBAL_VARIABLES))
WARNING: When executing eagerly variables do not necessarily have unique names
tf.train.import_meta_graph("empty_animal/snapshot-110.meta")
RuntimeError:` Exporting/importing meta graphs is not supported when eager execution is enabled.

Does it mean you used the eager mode? And that the network and its weights are not available in the end?

Thanks in advance