简体   繁体   English

我试图将图像预测到我的预训练深度学习分类模型

[英]I tried to predict an image to my pretrained deep learning classification model

When I test with validation data the output returned be with that shape [7.2918165e-06 3.2451030e-02 9.6753991e-01 1.7616502e-06] when I try to send a single image after I save the model and predict it the output be in shape [0.当我使用验证数据进行测试时,当我在保存模型并预测输出后尝试发送单个图像时,返回的输出具有该形状 [7.2918165e-06 3.2451030e-02 9.6753991e-01 1.7616502e-06]形状 [0. 1. 0. 0.] what is the problem 1. 0. 0.] 有什么问题

With the model.predict( ) is supposed to return the same shape as the model output with the valid values co-responsive from the input, and current training weights with a small change in the process when it is trainable.使用 model.predict( ) 应该返回与模型输出相同的形状,其有效值与输入共同响应,并且当前训练权重在可训练的过程中具有微小的变化。

The output of the last layer with activation, target layer output absorbed optimizer or loss Fn.具有激活的最后一层的输出,目标层输出吸收优化器或损失 Fn。 Some of the output is binary, entropy, logits, or multiple values when you working with layer output.当您使用层输出时,一些输出是二进制、熵、logits 或多个值。 ( see the shape is [ 2, 1 ] ) (看形状是 [ 2, 1 ] )

[ Sample ]: [ 样本 ]:

from os.path import exists

import tensorflow as tf
import matplotlib.pyplot as plt
import numpy as np

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""
[PhysicalDevice(name='/physical_device:GPU:0', device_type='GPU')]
None
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""
physical_devices = tf.config.experimental.list_physical_devices('GPU')
assert len(physical_devices) > 0, "Not enough GPU hardware devices available"
config = tf.config.experimental.set_memory_growth(physical_devices[0], True)
print(physical_devices)
print(config)   

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""
: Variables
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""
learning_rate = 0.001
global_step = 0
vocabulary_size = 5000
start = 0
limit = 128
delta = 1
embedding_size = 16
n_sample = 16

tf.compat.v1.disable_eager_execution()

# Input data.
inputs = tf.compat.v1.get_variable('X', dtype = tf.int32, initializer = tf.random.uniform(shape=[1], maxval=1, dtype=tf.int32, seed=10))
labels = tf.compat.v1.get_variable('Y', dtype = tf.int32, initializer = tf.random.uniform(shape=[1, 1], maxval=1, dtype=tf.int32, seed=10))

# Look up embeddings for inputs.
embeddings = tf.Variable(
tf.random.uniform([vocabulary_size, embedding_size], -1.0, 1.0)
)
embed = tf.nn.embedding_lookup(embeddings, inputs)

# Construct the variables for the NCE loss
nce_weights = tf.Variable(
    tf.random.uniform(shape=[vocabulary_size, embedding_size], maxval=255, dtype=tf.float32,)
)
nce_biases = tf.Variable(tf.zeros([vocabulary_size]))

# time we evaluate the loss.
loss = tf.reduce_mean(
tf.nn.nce_loss(nce_weights, nce_biases,
               labels=labels,
               inputs=embed,
               num_sampled=n_sample,
               num_classes=vocabulary_size),
name='loss'
)
optimizer = tf.compat.v1.train.ProximalAdagradOptimizer(
    learning_rate,
    initial_accumulator_value=0.1,
    l1_regularization_strength=0.2,
    l2_regularization_strength=0.1,
    use_locking=False,
    name='ProximalAdagrad'
)
training_op = optimizer.minimize(loss, name='minimize') 


"""""""""""""""""""""""""""""""""""""""""""""""""""""""""
: DataSet / Input
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""
X = np.reshape([ 500 ], (1))
Y = np.reshape([ 15 ], (1, 1))
history = [ ] 

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""
: Training / Optimize
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""
with tf.compat.v1.Session() as sess:
    sess.run(tf.compat.v1.global_variables_initializer())
    
    
    first_value = 500
    second_value = 15
    for i in range(1000):
        global_step = global_step + 1
        train_loss, temp = sess.run([loss, training_op], feed_dict={inputs:X, labels:Y})
        history.append(train_loss)
        
        print( 'steps: ' + str(i) )
        
        a = tf.constant([ first_value ])
        b = tf.constant([ second_value ])
        v = sess.run( [a, b] )
        print( v )
        
        first_value = first_value - i
        second_value = second_value - i
        
sess.close()

print( history )
plt.plot(history)
plt.show()
plt.close()

input('...')

[ Output ]: [ 输出 ]: 样本

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 深度学习 Model 从关键词预测点击 - Deep Learning Model to Predict Clicks from Keywords 如果我不将默认输入形状放入预训练模型中,深度学习程序的准确性会下降吗? - Does the accuracy of the deep learning program drop if I do not put in the default input shape into the pretrained model? 我想实现一个机器学习或深度学习 model 用于文本分类(100类) - I want to implement a machine learning or deep learning model for text classification (100 classes) 多标签图像分类训练预训练 CNN 期间的学习问题 - Learning problem during training pretrained CNN for multilabel image classification 为什么我得到“图形执行错误?” 什么时候预测深度学习模型 - Why i got 'Graph Execution Error?' when predict deep learning model Keras:解释model.predict()进行图像分类 - Keras: Interpretation of model.predict() for image classification Keras 的新秀:如何加载预训练的 MalConv model 以在我的数据中进行预测? - Rookie for Keras: how to load a pretrained MalConv model to predict in my data? 我想标准化我的图像数据以进行深度学习的预处理 - I want to standardise my image data for preprocessing for deep learning 确定深度学习的最佳分类阈值 model - Determine the best classification threshold value for deep learning model 迁移学习 - 将我的顶层与预训练模型合并,将准确率降至 0% - Transfer Learning - Merging my top layers with pretrained model drops accuracy to 0%
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM