Ad
TypeError: Cannot Perform Reduce With Flexible Type Keras
I have a model definition defined in a json file like below
{
"model": "Sequential",
"layers": [
{
"L1": "Conv2D(filters = '8', kernel_size=(3,3), strides=(1, 1), padding='valid', data_format='channels_last', activation='relu', use_bias=True, kernel_initializer='zeros', bias_initializer='zeros', kernel_regularizer=regularizers.l1(0.), bias_regularizer=regularizers.l1(0.), activity_regularizer=regularizers.l1(0.), kernel_constraint=max_norm(2.), bias_constraint=max_norm(2.), input_shape=(28,28,1))",
"L2": "Conv2D(filters = '8', kernel_size=(3,3), strides=(1, 1), padding='valid', data_format='channels_last', activation='relu', use_bias=True, kernel_initializer='zeros', bias_initializer='zeros', kernel_regularizer=regularizers.l1(0.), bias_regularizer=regularizers.l1(0.), activity_regularizer=regularizers.l1(0.), kernel_constraint=max_norm(2.), bias_constraint=max_norm(2.))",
"L3": "Flatten()",
"L4": "Dense(10, activation='softmax', use_bias=True, kernel_initializer='zeros', bias_initializer='zeros', kernel_regularizer='regularizers.l1(0.)', bias_regularizer='regularizers.l1(0.)', activity_regularizer='regularizers.l1(0.)', kernel_constraint=max_norm(2.), bias_constraint=max_norm(2.))"
}
]
}
When I load it in a model it throws the following error:
TypeError: cannot perform reduce with flexible type
For loading the model from json, I have the following code
with open('model_0.json','r') as fb:
con = json.load(fb)
print(con['layers'][0]['L1'])
model = Sequential()
model.add(eval(con['layers'][0]['L1']))
import pdb; pdb.set_trace()
model.add(eval(con['layers'][0]['L2']))
model.add(eval(con['layers'][0]['L3']))
model.add(eval(con['layers'][0]['L4']))
Does anyone have any idea ?
Ad
Answer
Your data should not be in string format. If it's in string format then change it to a numeric type.
import numpy as np
np.array(your_array).astype(np.float)
Ad
source: stackoverflow.com
Related Questions
- → What are the pluses/minuses of different ways to configure GPIOs on the Beaglebone Black?
- → Django, code inside <script> tag doesn't work in a template
- → React - Django webpack config with dynamic 'output'
- → GAE Python app - Does URL matter for SEO?
- → Put a Rendered Django Template in Json along with some other items
- → session disappears when request is sent from fetch
- → Python Shopify API output formatted datetime string in django template
- → Can't turn off Javascript using Selenium
- → WebDriver click() vs JavaScript click()
- → Shopify app: adding a new shipping address via webhook
- → Shopify + Python library: how to create new shipping address
- → shopify python api: how do add new assets to published theme?
- → Access 'HTTP_X_SHOPIFY_SHOP_API_CALL_LIMIT' with Python Shopify Module
Ad