Create TensorFlow Dataset with custom file format

Create TensorFlow Dataset with custom file format

I am trying to create a tf.data.Dataset, where filenames are mapped to Depth images. My images are saved as raw binary, 320*240*4 bytes per file. Images are 320x240 pixels, with 4 bytes representing a pixel.

I am trying to create a tf.data.Dataset, where filenames are mapped to Depth images. My images are saved as raw binary, 320*240*4 bytes per file. Images are 320x240 pixels, with 4 bytes representing a pixel.

I cannot figure out how to create a parsing function that will take a tf.Tensor filename, and return a (240, 320) tf.Tensor containing my image.

Here is what I've tried.

import tensorflow as tf
import numpy as np
import struct
import math
from os import listdir


class Dataset: def init(self): filenames = ["./depthframes/" + f for f in listdir("./depthframes/")]

    self._dataset = tf.data.Dataset.from_tensor_slices(filenames).map(Dataset._parse)

@staticmethod
def _parse(filename):
    img = DepthImage(filename)
    return img.frame

class DepthImage: def init(self, path): self.rows, self.cols = 240, 320 self.f = open(path, 'rb') self.frame = [] self.get_frame()

def _get_frame(self):
    for row in range(self.rows):
        tmp_row = []
        for col in range(self.cols):
            tmp_row.append([struct.unpack('i', self.f.read(4))[0], ])
        tmp_row = [[0, ] if math.isnan(i[0]) else list(map(int, i)) for i in tmp_row]
        self.frame.append(tmp_row)

def get_frame(self):
    self._get_frame()
    self.frame = tf.convert_to_tensor(np.array(self.frame).reshape(240, 320))

if name == "main": Dataset()

My error is as follows:

File "C:/Users/gcper/Code/STEM/msrdailyact3d.py", line 23, in init 
    self.f = open(path, 'rb')
TypeError: expected str, bytes or os.PathLike object, not Tensor


python numpy tensorflow image

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

Pure Python vs. NumPy vs. TensorFlow Performance Comparison

A performance comparison between pure Python, NumPy, and TensorFlow using a simple linear regression algorithm.

TensorFlow vs NumPy vs Pure Python: Performance Comparison

How much faster does the application run when implemented with NumPy instead of pure Python? What about TensorFlow? The purpose of this article is to begin to explore the improvements you can achieve by using these libraries.

NumPy Array Tutorial - Python NumPy Array Operations and Methods

Learn about NumPy Array, NumPy Array creation, various array functions, array indexing & Slicing, array operations, methods and dimensions,It also includes array splitting, reshaping, and joining of arrays. Even the other external libraries in Python relate to NumPy arrays.

NumPy in Python | NumPy Python Tutorial | Python Programming

NumPy in Python explains what exactly is Numpy and how it is better than Lists. It also explains various Numpy operations with examples.

Basic Data Types in Python | Python Web Development For Beginners

In the programming world, Data types play an important role. Each Variable is stored in different data types and responsible for various functions. Python had two different objects, and They are mutable and immutable objects.