Miguel Angel Castillo Martinez
Created February 12, 2022

Seed Image Processing Aided Analysis

A computer system will provide a set of tools to isolate, analyze, and track the seed features from digital images

IntermediateProtip119
Seed Image Processing Aided Analysis

Things used in this project

Hardware components

VCK5000 Versal Development Card
AMD VCK5000 Versal Development Card
ES1 Silicon Board
×1
C Mount Camera with optics
Generic inspection camera with 2 interchangeable optics and polarized crystal
×1
Polarized Light Ring
LED ring with polarized crystal
×1
Ryzen 7 5800X
This processor has not graphics integrated, a expansion board is required
×1
ProArt X570-CREATOR WIFI
In order to support the VCK5000, Graphics and SSD with the best performance possible
×1

Software apps and online services

Ubuntu 20.04
TensorFlow
TensorFlow
version GPU 1 .12
OpenCV
OpenCV
For postprocessing
GIMP
version 2.10

Story

Read more

Code

Minimal model implementation

Python
Trimmed UNet architecture to avoid GPU overflow in the training computer. the padding was added as 'same' to obtain the same resolution in the outputs
def UNetMinimal(H, W, C):
    image = Input(shape=(H, W, C) name)
     
    conv1 = Conv2D(64, (3, 3), padding='same', activation='relu')(image)
    conv2 = Conv2D(64, (1, 1), padding='same', activation='relu')(conv1)
    pool = MaxPooling2D(pool_size=(2, 2))(conv2)
    
    conv3 = Conv2D(128, (3, 3), padding='same', activation='relu')(pool)
    conv4 = Conv2D(128, (1, 1), padding='same', activation='relu')(conv3)
    
    convT = Conv2D(64, (2, 2), padding='same', activation='relu')(UpSampling2D(size=(2, 2))(conv4))
    merge = concatenate([convT, conv2], axis=3)
    conv5 = Conv2D(64, (3, 3), padding='same', activation='relu')(merge)
    conv6 = Conv2D(64, (1, 1), padding='same', activation='relu')(conv5)
    
    probability = Conv2D(2, (1, 1), activation='softmax')(conv6)

    return Model(inputs = image, outputs = probability)

Time measure for frozen model

Python
The main idea is test a frozen model in order to emulate a similar behaviour with the Vitis AI process.
import tensorflow as tf
from tensorflow.python.platform import gfile
from cv2 import imread, resize
import numpy as np
from glob import glob
from os.path import join as pJoin
import time

sess = tf.InteractiveSession()
f = gfile.FastGFile(pJoin('..', 'Models', '2A_20E_160x320D', '2A_20E_160x320D.pb'), 'rb')
graph_def = tf.GraphDef()
graph_def.ParseFromString(f.read())
f.close()

sess.graph.as_default()
tf.import_graph_def(graph_def)

output_tensor = sess.graph.get_tensor_by_name('import/conv2d_8/truediv:0')
input_tensor = sess.graph.get_tensor_by_name('import/input_1:0')
model_image_size = (input_tensor.shape.dims[1].value, input_tensor.shape.dims[2].value)

DatasetDir = pJoin('..', 'Dataset', 'Seeds', 'training', 'images')
ImagePaths = glob(pJoin(DatasetDir, '*.png'))
NImages = len(ImagePaths)

bundle = np.zeros((NImages, model_image_size[0], model_image_size[1], 3))
for i in range(NImages):
    I = imread(ImagePaths[i])
    I = I[:,:,0:3]/255
    input_image_size = (I.shape[1], I.shape[0])
    image = resize(I, (model_image_size[1], model_image_size[0]))
    bundle[i] = image
    
print(bundle.shape)

PrdIndex = [None]*NImages


time1 = time.time()
prediction = sess.run(output_tensor, {input_tensor: bundle})
    
time2 = time.time()
timetotal = time2 - time1

fps = NImages/timetotal
print("Throughput=%.2f fps, total frames = %.0f, time=%.4f seconds" %(fps, NImages, timetotal))

Credits

Miguel Angel Castillo Martinez

Miguel Angel Castillo Martinez

3 projects • 6 followers

Comments