Announcing the winners & finalists of the Dataiku Frontrunner Awards 2021! Read their inspiring stories

Code error - SyntaxError: invalid syntax

Swapnali
Level 3
Code error - SyntaxError: invalid syntax

I am executing following code:

start = time.time()
image_data_train = []
image_target_train = []
width = 15
height = 15

adress=dataiku.Folder("szRaxhwW").get_path()

for title in files:
        os.listdir(os.path.join(adress,title))
        counter = 0
        for i in data_train[title]:
                  img = cv2.imread(i,0)
                  #image_data_train.append(cv2.resize(img,(width, height)).flatten())
                  image_data_train.append(cv2.resize(img,(width, height), interpolation = cv2.INTER_AREA)

                  image_target_train.append(title)
                  counter += 1
                  if counter == sample_size:
                              break
       clear_output(wait=True)
       print("Compiled Class",title)
calculate_time = time.time() - start
print("Calculate Time",round(calculate_time,5))

 

I am getting error like:

ile "<ipython-input-16-0dfe9e7cb004>", line 18
image_target_train.append(title)
^
SyntaxError: invalid syntax

kindly help me to solve this

 

(Title edited by moderator to make it more descriptive. Original title "code error")

0 Kudos
3 Replies
AlexT
Dataiker
Dataiker

Hi,

Based on this the issue is actually the previous line.

 image_data_train.append(cv2.resize(img,(width, height), interpolation = cv2.INTER_AREA)

Can you try splitting that to separate lines and adding a print statement.

e.g

debug_ = cv2.resize(img,(width, height), interpolation = cv2.INTER_AREA)
image_data_train.append(debug_)

Could please share the full code sample and output you recieve?

 

 

0 Kudos
Swapnali
Level 3
Author

Thanks Alex fir your reply

Given solution did not work for me 

I am actually performing following use case

https://www.kaggle.com/mcahitgamsz/product-image-for-quality-inspection-scv-acc-99

0 Kudos
ClaudiusH
Community Manager
Community Manager

To me it looks like you are opening three brackets and are just closing two in this line and that's where the syntax error lies:

image_data_train.append(cv2.resize(img,(width, height), interpolation = cv2.INTER_AREA)
0 Kudos
A banner prompting to get Dataiku DSS