Код: Выделить всё
totalcharacter_indexoffirstchar_indexofsecondchar_.._indexoflastchar
Код: Выделить всё
def process_img(file_path):
label = get_label(file_path)
image = tf.io.read_file(file_path)
image = tf.image.decode_png(image, channels=1)
image = tf.image.convert_image_dtype(image, tf.float32)
target_shape = [695, 1204]
image = tf.image.resize_with_crop_or_pad(image, target_shape[0], target_shape[1])
# Encode the label
encoded_label = tf.py_function(func=encode_label, inp=[label], Tout=tf.float32)
encoded_label.set_shape([5, len(urdu_alphabets)])
return image, encoded_label
train_ds = train_ds.map(process_img, num_parallel_calls=tf.data.experimental.AUTOTUNE)
test_ds = test_ds.map(process_img, num_parallel_calls=tf.data.experimental.AUTOTUNE)
test_ds = test_ds.batch(32)
train_ds = train_ds.cache()
test_ds = test_ds.cache()
train_ds = train_ds.shuffle(len(train_ds))
test_ds = test_ds.prefetch(tf.data.AUTOTUNE)
print(train_ds)
print(test_ds)
Код: Выделить всё
Код: Выделить всё
def augment(image, label):
image = tf.image.random_flip_left_right(image)
image = tf.image.random_flip_up_down(image)
image = tf.keras.preprocessing.image.random_rotation(image, rg=15, row_axis=0, col_axis=1, channel_axis=2, fill_mode='nearest', cval=0.0, interpolation_order=1)
image = tf.image.random_zoom(image, [0.85, 0.85])
image = tf.image.random_shear(image, 0.3)
image = tf.image.random_shift(image, 0.1, 0.1)
return image, label
train_augmented_ds = train_ds.map(augment, num_parallel_calls=tf.data.AUTOTUNE)
train_augmented_ds = train_augmented_ds.prefetch(buffer_size=tf.data.AUTOTUNE)
Примечание. Я могу выполнить эти дополнения, загружая изображения без конвейеров TensorFlow с использованием массивов NumPy, но мой набор данных очень большой (1,1 миллиона изображений), поэтому мне нужен эффективный способ сделать это.
Буду благодарен за вашу помощь. Спасибо!
Подробнее здесь: https://stackoverflow.com/questions/788 ... ge-dataset