I am extracting the handwritten words from an image but getting error after following below code

  [tag: Load and preprocess images]
  images = []
  for image_path in image_paths:
      img = cv2.imread(image_path, cv2.IMREAD_GRAYSCALE)
      img = cv2.resize(img, (128, 32))
      images.append(img)
 
  images = np.array(images) / 255.0
  images = np.expand_dims(images, axis=-1)  ** # Add channel dimension for grayscale images**

  label_set = list(set(labels))  # Convert labels to a set and then a list
  label_to_index = {label: index for index, label in enumerate(label_set)}
  labels = [label_to_index[label] for label in labels]

 [tag: Convert labels to one-hot encoding]
 max_label_len = max([len(str(label)) for label in labels])  # Adjust this as per your needs
 labels_padded = np.zeros((len(labels), max_label_len))
 for i, label in enumerate(labels):
      labels_padded[i, :len(str(label))] = list(str(label))
 [tag: input format]
 input_img = Input(shape=(32, 128, 1), name='image_input')
 labels_input = Input(shape=(max_label_len,), name='label_input')
 input_length = Input(shape=(1,), name='input_length')
 label_length = Input(shape=(1,), name='label_length')
 
 

above code is the input for CNN layers ,I need improvement in that section

 [tag:CNN layers]
 x = Conv2D(32, (3, 3), activation='relu', padding='same')(input_img)
 x = MaxPooling2D((2, 2))(x)
 x = Conv2D(64, (3, 3), activation='relu', padding='same')(x)
 x = MaxPooling2D((2, 2))(x)

 ```This code giving me error at the time of training the dataset so I need to make some    changes in the above code ``` 
new_shape = (8, 2048)  # Ensure the reshaped dimensions match the total size of the tensor
x = Reshape(target_shape=new_shape)(x)  # Adjust shape to match the output tensor size
x = Bidirectional(LSTM(128, return_sequences=True))(x)
x = Bidirectional(LSTM(128, return_sequences=True))(x)
y_pred = Dense(len(label_set) + 1, activation='softmax', name='y_pred')(x)  # +1 for CTC blank       label
#Dense layer with softmax activation

def ctc_lambda_func(args):
y_true, y_pred, input_length, label_length = args
return tf.keras.backend.ctc_batch_cost(y_true, y_pred, input_length, label_length)

After Using above code getting following error

`—————————————————————————
ValueError Traceback (most recent call last)
Cell In[23], line 5
2 train_outputs = {‘ctc’: np.zeros((len(images),))}
4 # Train the model
—-> 5 ctc_model.fit(train_inputs, train_outputs, epochs=10, batch_size=32)
6 # Dummy data for CTC
7 train_outputs = {‘ctc’: np.zeros((len(images),))}

File ~AppDataLocalProgramsPythonPython312Libsite-packageskerassrcutilstraceback_utils.py:122, in filter_traceback..error_handler(*args, **kwargs)
119 filtered_tb = _process_traceback_frames(e.traceback)
120 # To get the full stack trace, call:
121 # keras.config.disable_traceback_filtering()
–> 122 raise e.with_traceback(filtered_tb) from None
123 finally:
124 del filtered_tb

Cell In[18], line 4, in ctc_lambda_func(args)
2 def ctc_lambda_func(args):
3 y_true, y_pred, input_length, label_length = args
—-> 4 return tf.keras.backend.ctc_batch_cost(y_true, y_pred, input_length, label_length)

ValueError: Exception encountered when calling Lambda.call().

Input tensor functional_1_1/ctc_1/Cast_2:0 enters the loop with shape (1, 1), but has shape (1, None) after one iteration. To allow the shape to vary across iterations, use the shape_invariants argument of tf.while_loop to specify a less-specific shape.

Arguments received by Lambda.call():
• inputs=[‘tf.Tensor(shape=(None, 1), dtype=float32)’, ‘tf.Tensor(shape=(None, 8, 4), dtype=float32)’, ‘tf.Tensor(shape=(None, 1), dtype=float32)’, ‘tf.Tensor(shape=(None, 1), dtype=float32)’]
• mask=[‘None’, ‘None’, ‘None’, ‘None’]
• training=True`

New contributor

Kedar Shinge is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật