Code error - SyntaxError: invalid syntax

Options
Swapnali
Swapnali Registered Posts: 38 ✭✭✭✭

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")

Answers

  • Alexandru
    Alexandru Dataiker, Dataiku DSS Core Designer, Dataiku DSS ML Practitioner, Dataiku DSS Adv Designer, Registered Posts: 1,209 Dataiker
    Options

    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?

  • Swapnali
    Swapnali Registered Posts: 38 ✭✭✭✭
    Options

    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

  • ClaudiusH
    ClaudiusH Alpha Tester, Dataiker Alumni, Registered Posts: 106 ✭✭✭✭✭✭
    edited July 17
    Options

    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)
Setup Info
    Tags
      Help me…