遮罩层与嵌入层冲突

时间:2019-02-14 06:28:32

标签: tensorflow keras

Tensorflow版本= 1.5 keras版本= 2.2.4 在GPU机器上训练模型时,一切正常,但是在CPU机器上训练或预测模型时,会发生某些情况。 看来,嵌入图层无法识别遮罩值-1。 这是我的代码:

constructor(props) {
        super(props);
            this.r2Ref = React.createRef();
            this.r3Ref = React.createRef();
            this.r4Ref = React.createRef();
            this.r5Ref = React.createRef();
    }

render() {
        return (
            <View style={SetStyle.settingsCont}>
            <ScrollView>

                <View style={SetStyle.contRate}>

                    <View style={SetStyle.rView}>
                        <Text style={SetStyle.rText}>Rate1</Text>
                        <TextInput style={SetStyle.rInput} keyboardType='numeric'
                            returnKeyType="next" onSubmitEditing={() => this.refs.r2Ref.focus()}></TextInput>
                    </View>
                    <View style={SetStyle.rView}>
                        <Text style={SetStyle.rText}>Rate2</Text>
                        <TextInput style={SetStyle.rInput} keyboardType='numeric'
                            ref={r2Ref => this.r2Ref = r2Ref}
                            returnKeyType="next" onSubimitEditing={() => this.refs.r3Ref.focus()}></TextInput>
                    </View>
                    <View style={SetStyle.rView}>
                        <Text style={SetStyle.rText}>Rate3</Text>
                        <TextInput style={SetStyle.rInput} keyboardType='numeric'
                        ref={r3Ref => this.r3Ref = r3Ref}
                        returnKeyType="next" onSubmitEditing={() => this.refs.r4Ref.focus()}></TextInput>
                    </View>
                    <View style={SetStyle.rView}>
                        <Text style={SetStyle.rText}>Rate4</Text>
                        <TextInput style={SetStyle.rInput} keyboardType='numeric'
                            ref={r4Ref => this.r4Ref = r4Ref}
                            returnKeyType="next" onSubmitEditing={() => this.refs.r5Ref.focus()}></TextInput>
                    </View>
                    <View style={SetStyle.rView}>
                        <Text style={SetStyle.rText}>Rate5</Text>
                        <TextInput style={SetStyle.rInput} keyboardType='numeric'
                            ref={r5Ref => this.r5Ref = r5Ref}></TextInput>
                    </View>
                </View>

            </ScrollView>
            </View>
        );
    }
}

然后用填充和-1预处理单词整数列表。 def make_model(): title_ids = Input(shape=(MAXLEN_CONTENT, ), name = 'title_content_ids') title_ids_mask = Masking(mask_value=-1, name='mask')(title_ids) # (?, 3075) embedding = Embedding(len(tok.word_index) + 1, 300, trainable=True) title_embed = embedding(title_ids_mask) # (?, 44, 300) title_encode = encode_rcnn(title_embed) # (?, 856) mlp0 = Dense(512,activation='relu',name='mlp0')(title_encode) mlp1 = Dense(256,activation='relu',name='mlp1')(mlp0) score = Dense(max(cate_label.values())+1 ,activation='softmax', name='mlp2')(mlp1) model = Model( title_ids, score) model.compile(loss='categorical_crossentropy', optimizer=Adam(lr=0.0001), metrics=['accuracy'] ) return model

这是错误:

title_content_pad_array = sequence.pad_sequences(title_content_ids_list, maxlen=MAXLEN_CONTENT, padding='post', truncating='post',value=-1)

再一次,我的GPU机器上的一切都很好。那么在CPU机器上运行的相同代码怎么了?

0 个答案:

没有答案
相关问题