Please look at:
  

      github.com/tensorflow/tensorflow
  

  
    
  
	  
  

  
    
      Keras model pickle-able but tf.keras model not pickle-able 90
    

    
      
        opened 
        
          
        
        Nov 29, 2019
      
      

        
          closed 
        
          
        
        Oct 4, 2021
      
        

      
        
          
          Edwin-Koh1
        
      
    

    
        stat:awaiting response
        stat:awaiting tensorflower
        type:bug
        stalled
        comp:keras
        TF 2.5
    
  


  
    **System information**
- Windows 10 
- Tensorflow 2.0 (CPU)
- joblib 0.14.0
…- Python 3.7.5
- Keras 2.3.1

Hello everybody! This is my first post so please forgive me if I have missed something. So I'm trying to use a genetic algorithm to train and evaluate multiple NN architectures so I need to parallelize them on a multi-core CPU. Therefore I have used joblib to try to parallelize this. However, I was stuck on my tf.keras code because it wasn't pickleable. After many hours of debugging I finally realised that the tf.keras models are not pickleable whereas keras models are.

**Describe the current behavior**
The code below works but if you replaced keras with tf.keras, there will be an error:
**Could not pickle the task to send it to the workers.**

**Describe the expected behavior**
Moving forward, tf.keras should be replacing keras and therefore tf.keras should also be pickleable.

**Code to reproduce the issue**
```
#The following is a simple code to illustrate the problem:
from joblib import Parallel, delayed
import keras
import tensorflow as tf

def test():
    model = keras.models.Sequential()
    return

Parallel(n_jobs=8)(delayed(test)(i) for i in range(10)) #this works as intended

def test_tf():
    model = tf.keras.models.Sequential()
    return

Parallel(n_jobs=8)(delayed(test_tf)(i) for i in range(10)) #this will spit out the error above
```

**Other comments**
I guess a quick fix would just be to replace all the existing code with tf.keras to just keras but seeing as keras support will be discontinued and absorbed by Tensorflow 2.0, I think this should be fixed.
  

  

  
    
    
  

  


I suggest to test this with TF 2.6.x or TF 2.7rc