1

I'm trying to train Alexnet on a test harness and I am passing the harness the model definition (which is written in TF1.X). All parts of the test harness are functioning properly, but when I pass the model for training I am met with

module 'tensorflow' has no attribute 'contrib'

since my model definition is old and the test harness is running the latest-and-greatest TF2.0 (tensorflow 2.0.0a0).

The posts I've found that address this problem are the following:

Tensorflow 2.0 - AttributeError: module 'tensorflow' has no attribute 'Session'

Module 'tensorflow' has no attribute 'contrib'

but none of them actually solve the issue.

What I've tried:

  • A recommendation above suggests I upgrade my TF1.X code to TF2.0 by passing files or folders to tf_upgrade_v2 as described here, but from the release notes (and actually running it) I find that .contrib is the only library whose conversion isn't supported.

  • The other recommendation (here) was that I could achieve the same results by modifying environmental variables using the os module, but the test harness I'm working in doesn't allow me to access environmental variables, so this avenue won't work.

  • From the TF website I found this which describes a method for converting tf.contrib.slim into TF2.0 (seemed promising) but given their proposed solution of tf.contrib.slim > v1.layers > keras this will involve a significant amount of work on my end so I would like to exhaust any other available options before going down this rabbit hole.

What are my options for rewriting Alexnet in TF2.0?

Eduardo Barrera
  • 516
  • 7
  • 17
  • What do you mean by model definition? It's architecture? If so, have you tried saving the weights of your TF1 model, recreating a model (in TF2) with the same architecture and then loading the weights? https://www.tensorflow.org/api_docs/python/tf/keras/Model#load_weights – Hichame Yessou Jan 22 '20 at 16:15
  • Yes, it is the model architecture I'm referring to. It uses functions like `tf.contrib.slim`, which I am unable to rewrite in TF2.0 (without significant effort, as above). – Eduardo Barrera Jan 22 '20 at 18:59
  • @EduardoBarrera If you found any working solution please share it. Thanks – Siamak Mar 30 '20 at 16:59
  • 1
    @SiamakSiaSoft I found a PyTorch implementation that my test harness worked with, and scrapped trying to convert from TF1.X to TF2.0. Sorry is this isn't a solution on your end! – Eduardo Barrera Mar 30 '20 at 20:52

0 Answers0