core

Fill in a module description here
path = Path(r'/home/goni/workspace/projects/easy_pin_detection/data_first/Trainingsdata_1024_1224')
path.ls()
(#3) [Path('/home/goni/workspace/projects/easy_pin_detection/data_first/Trainingsdata_1024_1224/models'),Path('/home/goni/workspace/projects/easy_pin_detection/data_first/Trainingsdata_1024_1224/X'),Path('/home/goni/workspace/projects/easy_pin_detection/data_first/Trainingsdata_1024_1224/y')]

source

Preprocess

 Preprocess (image_path:Union[pathlib.Path,str],
             label_path:Union[pathlib.Path,str], im_height:int=224,
             im_width:int=224, bf_size:int=30, bs:int=8,
             one_channel:bool=False, test_size:float=0.2)
preprocess_obj = Preprocess(
                           image_path=path/'X',
                           label_path=path/'y',
                           im_height=IMAGE_HEIGHT,
                           im_width=IMAGE_WIDTH,
                           bs=BATCH_SIZE,
                           one_channel=False,
                           test_size=0.2
                           )

Augmentation needs to be done before resizing the image - - - - - - - - - - - - - - - - -


source

Preprocess.show_image

 Preprocess.show_image (im_file)

source

Preprocess.read_image

 Preprocess.read_image (im_file, one_channel=False)
fn =str((path/'X').ls()[0])
fn_lbl = str((path/'y').ls()[0])
img_ = preprocess_obj.read_image(fn, one_channel=True)
test_eq(img_.numpy().shape, (1024, 1224, 1))
img_ = preprocess_obj.read_image(fn, one_channel=False)
lbl_ = preprocess_obj.read_image(fn_lbl, one_channel=False)
test_eq(img_.numpy().shape, (1024, 1224, 3))
2023-04-18 10:54:58.979576: I tensorflow/compiler/xla/stream_executor/cuda/cuda_gpu_executor.cc:967] could not open file to read NUMA node: /sys/bus/pci/devices/0000:01:00.0/numa_node
Your kernel may have been built without NUMA support.
2023-04-18 10:54:58.996838: I tensorflow/compiler/xla/stream_executor/cuda/cuda_gpu_executor.cc:967] could not open file to read NUMA node: /sys/bus/pci/devices/0000:01:00.0/numa_node
Your kernel may have been built without NUMA support.
2023-04-18 10:54:58.997556: I tensorflow/compiler/xla/stream_executor/cuda/cuda_gpu_executor.cc:967] could not open file to read NUMA node: /sys/bus/pci/devices/0000:01:00.0/numa_node
Your kernel may have been built without NUMA support.
2023-04-18 10:54:58.999003: I tensorflow/core/platform/cpu_feature_guard.cc:193] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN) to use the following CPU instructions in performance-critical operations:  SSE4.1 SSE4.2 AVX AVX2 AVX512F AVX512_VNNI FMA
To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.
2023-04-18 10:54:59.003367: I tensorflow/compiler/xla/stream_executor/cuda/cuda_gpu_executor.cc:967] could not open file to read NUMA node: /sys/bus/pci/devices/0000:01:00.0/numa_node
Your kernel may have been built without NUMA support.
2023-04-18 10:54:59.004910: I tensorflow/compiler/xla/stream_executor/cuda/cuda_gpu_executor.cc:967] could not open file to read NUMA node: /sys/bus/pci/devices/0000:01:00.0/numa_node
Your kernel may have been built without NUMA support.
2023-04-18 10:54:59.005818: I tensorflow/compiler/xla/stream_executor/cuda/cuda_gpu_executor.cc:967] could not open file to read NUMA node: /sys/bus/pci/devices/0000:01:00.0/numa_node
Your kernel may have been built without NUMA support.
2023-04-18 10:55:00.242731: I tensorflow/compiler/xla/stream_executor/cuda/cuda_gpu_executor.cc:967] could not open file to read NUMA node: /sys/bus/pci/devices/0000:01:00.0/numa_node
Your kernel may have been built without NUMA support.
2023-04-18 10:55:00.243227: I tensorflow/compiler/xla/stream_executor/cuda/cuda_gpu_executor.cc:967] could not open file to read NUMA node: /sys/bus/pci/devices/0000:01:00.0/numa_node
Your kernel may have been built without NUMA support.
2023-04-18 10:55:00.243526: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1700] Could not identify NUMA node of platform GPU id 0, defaulting to 0.  Your kernel may not have been built with NUMA support.
2023-04-18 10:55:00.243628: I tensorflow/compiler/xla/stream_executor/cuda/cuda_gpu_executor.cc:967] could not open file to read NUMA node: /sys/bus/pci/devices/0000:01:00.0/numa_node
Your kernel may have been built without NUMA support.
2023-04-18 10:55:00.243890: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1613] Created device /job:localhost/replica:0/task:0/device:GPU:0 with 1189 MB memory:  -> device: 0, name: NVIDIA GeForce MX450, pci bus id: 0000:01:00.0, compute capability: 7.5

source

Preprocess.augmentation_

 Preprocess.augmentation_ (im_height:int, im_width:int,
                           image:tensorflow.python.framework.tensor.Tensor
                           ,
                           mask:tensorflow.python.framework.tensor.Tensor)

source

Preprocess.show_aug

 Preprocess.show_aug (image, mask, original_image=None,
                      original_mask=None)

source

Preprocess.read_aug

 Preprocess.read_aug (im_file:str, lbl_file:str, one_channel:bool=False,
                      aug:bool=False)
im, msk = preprocess_obj.read_aug(im_file=fn, lbl_file=fn_lbl, one_channel=False, aug=True)
im.shape, msk.shape
test_eq_type(type(im), np.ndarray), test_eq_type(type(msk), np.ndarray);
#preprocess_obj.show_aug(image=im, mask=msk, original_image=img_.numpy(), original_mask=lbl_.numpy())

source

Preprocess.normalize

 Preprocess.normalize
                       (image:Union[numpy.ndarray,tensorflow.python.framew
                       ork.tensor.Tensor], min=0)
im.shape
(1224, 1024, 3)
norm_img = preprocess_obj.normalize(im)
np_img_ = norm_img.numpy()
np_img_.min(), im.min(), np_img_.max(), im.max()
#test_eq(np_img_.min(),0.0), test_eq(np_img_.max(),1.0);
(0.0, 0, 0.87058824, 222)

source

Preprocess.process_image_and_mask

 Preprocess.process_image_and_mask (im_file:str, lbl_file:str,
                                    norm:bool=True,
                                    one_channel:bool=False,
                                    aug_data:bool=True)
im, msk = preprocess_obj.process_image_and_mask(im_file=fn, lbl_file=fn_lbl, norm=True, one_channel=False)
type(im),  type(msk)
(tensorflow.python.framework.ops.EagerTensor,
 tensorflow.python.framework.ops.EagerTensor)
test_eq(im.numpy().shape, (IMAGE_HEIGHT,IMAGE_WIDTH,3))
test_eq(msk.numpy().shape, (IMAGE_HEIGHT,IMAGE_WIDTH,3))

Create dataset


source

Preprocess.process_data

 Preprocess.process_data (image, label, norm:bool=True,
                          one_channel:bool=False, aug_data:bool=True)

source

Preprocess.set_shapes

 Preprocess.set_shapes (img, label, img_shape)

source

Preprocess.create_dataset

 Preprocess.create_dataset (images, labels, train:bool=True,
                            norm:bool=True, aug:bool=True)

source

Preprocess.create_train_test_dataset

 Preprocess.create_train_test_dataset ()
one_batch = next(iter(train_ds))
2023-04-18 10:55:42.416394: W tensorflow/core/kernels/data/cache_dataset_ops.cc:856] The calling iterator did not fully read the dataset being cached. In order to avoid unexpected truncation of the dataset, the partially cached contents of the dataset  will be discarded. This can happen if you have an input pipeline similar to `dataset.cache().take(k).repeat()`. You should use `dataset.take(k).cache().repeat()` instead.
images_ds, masks_ds = one_batch

source

convert_np_and_uint8

 convert_np_and_uint8 (img:tensorflow.python.framework.tensor.Tensor)

Convert img to np.array and uint8


source

convert_one_channel

 convert_one_channel (img:tensorflow.python.framework.tensor.Tensor)

Convert image to one channel


source

Preprocess.create_color_mask

 Preprocess.create_color_mask (mask:Union[<built-
                               infunctionarray>,tensorflow.python.framewor
                               k.tensor.Tensor], img:Union[<built-infuncti
                               onarray>,tensorflow.python.framework.tensor
                               .Tensor], threshold:float=0.5)

Creating color mask for segmentation


source

Preprocess.display_np_batch

 Preprocess.display_np_batch (images:numpy.ndarray, masks:numpy.ndarray,
                              threshold:float=0.5)

Displaying batch of images and masks


source

Preprocess.display_ds

 Preprocess.display_ds
                        (ds:tensorflow.python.data.ops.dataset_ops.Dataset
                        V2)
#preprocess_obj.display_ds(train_ds)

source

foo

 foo ()