C2_W2_Assignment

Hi,

I am getting errors for exercise#2 (get_records) when doing the following

Read the example data (output is a protocol buffer message)

    example.ParseFromString(serialized_example)

Error Message:
TypeError: descriptor ‘ParseFromString’ for ‘google.protobuf.pyext._message.CMessage’ objects doesn’t apply to a ‘bytes’ object

Can someone help, please.

Hi @obiii , so can you tell me your definition of “serialized example”?
regards,

Hi,

This is the code I have.

def get_records(dataset, num_records):
‘’‘Extracts records from the given dataset.
Args:
dataset (TFRecordDataset): dataset saved by ExampleGen
num_records (int): number of records to preview
‘’’

# initialize an empty list
records = []

### START CODE HERE
# Use the `take()` method to specify how many records to get
for tfrecord in dataset.take(num_records):
    
    # Get the numpy property of the tensor
    serialized_example = tfrecord.numpy()
    
    # Initialize a `tf.train.Example()` to read the serialized data
    example = tf.train.Example
    
    # Read the example data (output is a protocol buffer message)
    example.ParseFromString(serialized_example)
    
    # convert the protocol bufffer message to a Python dictionary
    example_dict = (MessageToDict(example))
    
    # append to the records list
    records.append(example_dict)
    
### END CODE HERE
return records

Hi @obiii ,
I believe to follow the instruction literally is key to resolve the issue:

# Initialize a tf.train.Example() to read the serialized data

I hope it helps,
regards,