保存分类Keras模型以输出分类名称

我创建了一个模型,用于输出某些图像的类别名称(而不是概率)

我想保存模型,以便用户能够加载它,并使用它来预测特定图像的类别。我不想让用户知道我可以预测多少个类,换句话说,我不想为用户提供类列表及其“标签”,以便他将其编入索引。

我将模型附加如下:

<meta name="viewport" content="width=device-width,initial-scale=1.0">

    <llink rel="stylesheet" href="https://ssl.gstatic.com/docs/script/css/add-ons1.css">
    <script src="//ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
    <style>
    
@media screen and (max-width:980px) {
html,body,iframe#sandboxFrame,.full_size {
    margin: 0;
    padding: 0;
    height: 100%;
    width: 100%;
    background-color: #eeeeee;
}
body {
    color: #222;
/*    font-size: 2.3vw !important; */
/*    line-height:2.8vw !important; */
    background-color: #eeeeee;
}

.contacts { 
    width: 95%; 
    margin: auto;  
    -moz-box-sizing: border-box;
    box-sizing: border-box;
    overflow-y: auto;
    padding: 12px;
    } 
    
    h2 {
    color: #000;
/*    font-size: 3.2vw !important; */
/*    line-height:4.2vw !important; */
    text-align: center;
    border-bottom: 1px #333 solid;
    padding-bottom: 15px;
/*    margin-bottom: 30px; */
}
    .control-label {
    display: flex;
    min-width: 29%!important;
    color: #222;
    font-size: 3vw !important;
    line-height:3vw !important;
    text-align: left;
    }
    
    input[type="date"],input[type="datetime"],input[type="datetime-local"],input[type="email"],input[type="month"],input[type="number"],input[type="password"],input[type="search"],input[type="tel"],input[type="text"],input[type="time"],input[type="url"],input[type="week"],select[multiple],select[size],textarea {
    background: #fff;
    border: 2px solid #9e9e9e;
    -moz-border-radius: 5px;
    -webkit-border-radius: 5px;
    border-radius: 5px;
    -moz-box-sizing: border-box;
    -webkit-box-sizing: border-box;
    box-sizing: border-box;
    color: #000;
    font-family: arial,sans-serif;
    font-size: 3vw !important;
    font-weight: normal;
    margin: auto;
    outline: 0;
    padding: 4px;
    width: 100%;
    float:none;
    height: 65px;
    text-align: left;
}

.button.action,.button.blue,button.action,button.blue,input[type="button"].action,input[type="button"].blue,input[type="submit"].action,input[type="submit"].blue {
    background: -moz-linear-gradient(top,#c42839,#c42839);
    background: -ms-linear-gradient(top,#c42839);
    background: -o-linear-gradient(top,#c42839);
    /* background-color: #c42839!important; */
    border: 1px solid #3079ed;
    color: #fff;
    margin-top: 15px;
    margin-bottom: 10px;
    margin-left: 35%;
    width: 30%;
    border-radius: 55px;
    font-family: arial,sans-serif;
    font-size: 3vw !important;
    font-weight: bold;
    height: 75px;
    line-height: 30px;
    }

.button,button,input[type="button"],input[type="image"],input[type="reset"],input[type="submit"] {
    background: -moz-linear-gradient(top,#c42839);
    background: -webkit-linear-gradient(top,#c42839);
    background: linear-gradient(top,#c42839);
    border: 1px solid #dcdcdc;
    -moz-border-radius: 2px;
    -webkit-border-radius: 2px;
    border-radius: 2px;
    -moz-box-shadow: none;
    -webkit-box-shadow: none;
    box-shadow: none;
    color: #333;
    cursor: default;
    font-family: arial,sans-serif;
    font-size: 14px;
    font-weight: bold;
    height: 35px;
    line-height: 27px;
    margin: 0;
    min-width: 72px;
    outline: 0;
    padding: 0 8px;
    text-align: center;
    white-space: nowrap;    
}
#message {
    text-align: center;
    margin-top: -10px;
    font: 15px/20px arial,sans-serif !important;
    margin-bottom: 30px;
}
}

@media screen and (min-width:981px) {
html,.full_size {
    margin: 0;
    padding: 0;
    height: 100%;
    width: 100%;
    background-color: #eeeeee;
}
.contacts { 
    width: 560px; 
    margin: 0 auto;  
    -moz-box-sizing: border-box;
    box-sizing: border-box;
    overflow-y: auto;
    padding: 12px;
    } 


    h2 {
    color: #000;
    font: 16px/24px arial,sans-serif normal;
    text-align: center;
    border-bottom: 1px #333 solid;
    padding-bottom: 15px;
    margin-bottom: 30px;
}
    .control-label {
    display: inline-block;
    min-width: 29%!important;
    color: #222;
    font-size: 15px !important;
    line-height:20px !important;
/*    font: 15px/20px arial,sans-serif; */
    text-align: left;
    }
    
    input[type="date"],textarea {
    background: #fff;
    border: 1px solid #9e9e9e;
    -moz-border-radius: 5px;
    -webkit-border-radius: 5px;
    border-radius: 5px;
    -moz-box-sizing: border-box;
    -webkit-box-sizing: border-box;
    box-sizing: border-box;
    color: #000;
    font-family: arial,sans-serif;
    font-size: 13px;
    font-weight: normal;
    margin: 0;
    outline: 0;
    padding: 4px;
    width: 70%;
    float:right;
    text-align: left;
}

.button.action,#c42839);
    /* background-color: #c42839!important; */
    border: 1px solid #3079ed;
    color: #fff;
    margin-top: 25px;
    margin-bottom: 20px;
    margin-left: 37%;
    width: 26%;
    border-radius: 55px;
    font-family: arial,sans-serif;
    font-size: 14px;
    font-weight: bold;
    height: 35px;
    line-height: 27px;
}
.button,sans-serif;
    font-size: 14px;
    font-weight: bold;
    height: 35px;
    line-height: 27px;
    margin: 0;
    min-width: 72px;
    outline: 0;
    padding: 0 8px;
    text-align: center;
    white-space: nowrap;
}
#message {
    text-align: center;
    margin-top: -20px;
    font: 15px/18px arial,sans-serif;
    margin-bottom: 20px;
}
}
.center {
  display: block;
  margin-left: auto;
  margin-right: auto;
  width: 50%;
  filter: brightness(0.94);
  margin-bottom: 50px;
}
.center_text{
    text-align: center;
}
    </style>

<div class="contacts">
  <h2 class="title">Google Contacts Updater</h2>
  <p id="message">
    Please,fill the form below to update your contact information.<br>Thanks for your cooperation! 
  </p>

  <form id="contactform">
    <p>
      <label class="control-label" for="inputName">Your Name</label>
      <input type="text" id="inputFULL_NAME" placeholder="Full Name" value="<?= name ?>">
    </p>

    <p>
      <label class="control-label" for="inputEmail">Email Address</label>
      <input type="text" id="inputHOME_EMAIL" class="input-large" placeholder="i.e.: name@yourdomain.com">
    </p>
    
    <p>  
      <label class="control-label" for="inputMobilePhone">Mobile Phone</label>
      <input type="text" id="inputMOBILE_PHONE" class="input-medium" placeholder="">
    </p>
    
    <p>
      <label class="control-label" for="inputAddressWork">Street Address</label>
      <input type="text" id="inputHOME_ADDRESS" class="input-xlarge" placeholder="">
    </p>

    <p>
      <label class="control-label" for="inputSkype">Skype</label>
      <input type="text" id="inputSKYPE" class="input-small"  placeholder="@username">
    </p>

    <p><label class="control-label" for="inputTwitter">Twitter</label>
      <input type="text" id="inputTWITTER" class="input-small" placeholder="@username">
    </p>  
    
    <p>
      <label class="control-label" for="inputDOB">Birthday</label>
      <input type="text" id="inputBIRTHDAY" class="input-small" placeholder="MM/DD/YYYY">
    </p>

    <p>
      <label class="control-label" for="inputBlog">Website</label>
      <input type="text" id="inputBLOG" class="input" placeholder="i.e.: yourwebsite.com">
    </p>
    <p>
      <input type="hidden" name="id" value="<?= id; ?>" />
      <input type="submit" class="btn blue" value="Update Contact" onclick="updateGoogleContacts(); return false;">
    </p>
  </form>
  <hr />
  <p class="center_text">If you have any questions send an email to <a href="mailto:info@testdomain.com?Subject=Google%20Contacts%20Updater%20Script">info@testdomain.com</a></p>

</div>



<script>

  function progress() {
    $("#message").html("Your contact details have been updated. Thanks!");
    return;
  }

  function updateGoogleContacts() {

    var contact = {};

    contact.FULL_NAME    = $("input#inputFULL_NAME").val();
    contact.HOME_EMAIL   = $("input#inputHOME_EMAIL").val();
    contact.HOME_ADDRESS = $("input#inputHOME_ADDRESS").val();
    contact.MOBILE_PHONE = $("input#inputMOBILE_PHONE").val();
    contact.SKYPE        = $("input#inputSKYPE").val();
    contact.TWITTER      = $("input#inputTWITTER").val();
    contact.BLOG         = $("input#inputBLOG").val();
    contact.BIRTHDAY     = $("input#inputBIRTHDAY").val();
    contact.id           = "<?= id ?>";

    google.script.run.withSuccessHandler(progress).UpdateContact(contact);      

    $("#contactform").hide();
    $("#message").html("Updating your contact...");

    return false;

  }

</script>

其中

labels = Lambda(lambda x: K.argmax(x,axis=-1))(model.output)
categories = Lambda(lambda x: tf.gather(classes,x))(labels)
final_model = Model(model.input,categories)

我正在使用classes=["dog","cat",...,"table"] 方法保存该模型,但是当我要加载模型时,必须提供mode.save :(如下:

custom_objects

有办法避免吗?

sy20031983 回答:保存分类Keras模型以输出分类名称

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3125139.html

大家都在问