簡體   English   中英

如何在 pycharm 中腌制 model?

[英]How to pickle model in pycharm?

我的 CNN Model在這里我已經為我的 model 編寫了代碼,我正在嘗試腌制這個 model 但它給了我錯誤

    cnn = Sequential([
            # layers.Conv2D(filters=32, kernel_size=(3, 3), activation='relu', input_shape=(50, 50, 3)),
            # layers.MaxPooling2D((2, 2),padding="valid"),
            # testinaccur=68,trainaccur=75
        
            layers.Conv2D(filters=64, kernel_size=(3, 3), activation='relu', input_shape=(50, 50, 3), padding="same"),
            layers.MaxPooling2D((2, 2)),
        
            layers.Conv2D(filters=128, kernel_size=(3, 3), activation='relu', padding="same"),
            layers.MaxPooling2D((2, 2)),
        
            layers.Conv2D(filters=256, kernel_size=(3, 3), activation='relu', padding="same"),
            layers.MaxPooling2D((2, 2)),
        
            layers.Conv2D(filters=512, kernel_size=(3, 3), activation='relu', padding="same"),
            layers.MaxPooling2D((2, 2)),
        
            layers.Flatten(),
            layers.Dense(64, activation='relu'),
            # layers.Dropout(0.3),
            layers.Dense(7, activation='softmax')
        ])
        
        cnn.compile(optimizer='adam',
                      loss='sparse_categorical_crossentropy',
                      metrics=['accuracy'])
        cnn.fit(trainx, y_train,batch_size=128, epochs=30)
    
        y_pred = cnn.predict(testx)
        y_pred_classes = [np.argmax(element) for element in y_pred]

   
   

 **I had written code for pickle**

這個泡菜文件也在目錄中創建

 pickle.dump(cnn, open('model.pkl', 'wb'))

  **After running this line I am getting error**

加載 model 后,這是我面臨的問題

pickled_model = 
     pickle.load(open('C:/Users/ABHISHEK/PycharmProjects/cervical_project/model.pkl', 'rb')) 


  **Error**


    FileNotFoundError: Unsuccessful TensorSliceReader constructor: Failed to find any matching files for ram://5662344f-e2fd-4175-9583-4ed4fec7fc7f/variables/variables
 You may be trying to load on a different device from the computational device. Consider setting the `experimental_io_device` option in `tf.saved_model.LoadOptions` to the io_device such as '/job:localhost'.

不要腌制tensorflow / keras型號。 使用隨您的順序 model 提供的保護程序/加載程序(例如.h5格式),如文檔中所述

保存 Keras model:

model = ...  # Get model (Sequential, Functional Model, or Model subclass)
model.save('path/to/location')

將 model 裝回:

from tensorflow import keras
model = keras.models.load_model('path/to/location')

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM