下面是我使用的路由代码:imgs_inputfn()> NNTrainEvalBuild(),我知道我是使用TFRecords的,
解析它,就像解码它一样。
Out(图片和标签)
然后对图像进行一些处理(不确定是否重要)。
然后再次将其变成张量,张量只是带有标签的字典。
1)使用张量如何将其输入到(NNTrainEvalBuild)的输入中,NNTainEvalBuild只是我的思维定势。但似乎大脑没有输入。
2)如果NNTrainEvalBuild实际上只是一个大脑*,而我所做的只是定义NeuralNetwork / Brain 那么我该如何用张量/解析的TFrecords训练它。
我应该做一个手动循环来训练还是tf已经有一个使用参数调用函数的模块? 例如:Handsome.py,具有以下功能:TrainBrain(tensor):找到大脑,用张量进行大脑训练
那么我要做的就是
导入tf.Mansome作为OMG
OMG.TrainBrain(张量)
但即使这样,函数如何占用我的(Brain / NeuralNetwork)?
3,可视化)就像我有一个大脑(NN)和一个有图片的世界(TFRecords)。
但是反射光似乎是红外线,所以我将其处理为可见光(张量)
但是不知何故,大脑没有眼睛(有些功能需要张量和N.N.将它们连接在一起。)
??任何帮助都会非常有用,因为我一直在寻找具有高级API支持的教程。
Win-10,TF-1.15,使用Virtual Env for ML,
import TensorFlow
def imgs_input_fn(tfRecordspath,perform_shuffle=False,repeat_count=1,batch_size=1):
def parse_function(serialized):
features = \
{
'image': tf.FixedLenFeature([],tf.string),'label': tf.FixedLenFeature([],tf.int64)
}
# Parse the serialized data so we get a dict with our data.
parsed_example = tf.parse_single_example(serialized,features)
Image_ypix=720
Image_xpix=480
Input_name="kakoii"
# Get the image as raw bytes.
image_shape = tf.stack([Image_ypix,Image_xpix,3])
image_raw = parsed_example['image']
label = tf.cast(parsed_example['label'],tf.float32)
# Decode the raw bytes so it becomes a tensor with type.
image = tf.decode_raw(image_raw,tf.uint8)
image = tf.cast(image,tf.float32)
image = tf.reshape(image,image_shape)
#image = tf.subtract(image,pixel_val?) # Zero-center by mean pixel,too complex
image = tf.reverse(image,axis=[2]) # 'RGB'->'BGR'
tensor = dict(zip([input_name],[image])),[label]
return tensor
tfRecordspath=input("TFRecords's path:")
dataset = tf.data.TFRecordDataset(tfRecordspath)
# Parse the serialized data in the TFRecords files.
# This returns TensorFlow tensors for the image and labels.
dataset = dataset.map(parse_function)
if perform_shuffle:
# Randomizes input using a window of 256 elements (read into memory)
dataset = dataset.shuffle(buffer_size=256)
dataset = dataset.repeat(repeat_count) # Repeats dataset this # times
dataset = dataset.batch(batch_size) # Batch size to use
iterator = dataset.make_one_shot_iterator()
batch_features,batch_labels = iterator.get_next()
return batch_features,batch_labels
def oldTrainorEval():
train_spec = tf.estimator.TrainSpec(input_fn=lambda: imgs_input_fn(path_tfrecords_train,perform_shuffle=True,repeat_count=5,batch_size=20),max_steps=500)
eval_spec = tf.estimator.EvalSpec(input_fn=lambda: imgs_input_fn(path_tfrecords_test,batch_size=1))
tf.estimator.train_and_evaluate(est_catvsdog,train_spec,eval_spec)
def NNTrainEvalBuild():
model=tf.keras.Sequential([
tf.keras.layers.flatten(input_shape=(720,480)),#tf.keras.layers.flatten(10,inputshape=(image_ypixel,image_xpixel)),tf.keras.layers.Dense(1024,activation=tf.nn.relu),tf.keras.layers.Dense(32,tf.keras.layers.Dense(8,activation=tf.nn.softmax)
])
#tf.keras.layer.dense(unit=4,),concept4 unit,out8,using upper as trial