【python 错误解决】Object arrays cannot be loaded when allow_pickle=False

展开阅读全文

Keras, Tensorflow, ValueError

12-19

把csdn上一个颜值打分程序放到jupyter notebook上跑,程序如下: ``` from keras.applications import ResNet50 from keras import optimizers from keras.layers import Dense, Dropout from keras.callbacks import EarlyStopping, ReduceLROnPlateau, ModelCheckpoint from keras.backend.tensorflow_backend import set_session os.environ['CUDA_VISIBLE_DEVICES'] = '1' config = tf.ConfigProto() config.gpu_options.allow_growth = True set_session(tf.Session(config=config)) batch_size = 32 target_size = (224, 224) resnet = ResNet50(include_top=False, pooling='avg') resnet.trainable = False # keras.backend.clear_session() # tf.reset_default_graph() model = Sequential() model.add(resnet) model.add(Dropout(0.5)) model.add(Dense(1, activation='sigmoid')) print(model.summary()) model.compile(optimizer=optimizers.SGD(lr=0.001), loss='mse') callbacks = [EarlyStopping(monitor='val_loss', patience=5, verbose=1, min_delta=1e-4), ReduceLROnPlateau(monitor='val_loss', patience=3, factor=0.1, epsilon=1e-4), ModelCheckpoint(monitor='val_loss', filepath='weights/resnet50_weights.hdf5', save_best_only=True, save_weights_only=True)] train_file_list, test_file_list = read_data_list() train_steps_per_epoch = math.ceil(len(train_file_list) / batch_size) test_steps_per_epoch = math.ceil(len(test_file_list) / batch_size) train_data = DataGenerator(train_file_list, target_size,batch_size) test_data = DataGenerator(test_file_list, target_size, batch_size) model.fit_generator(train_data, steps_per_epoch=train_steps_per_epoch, epochs=30, verbose=1, callbacks=callbacks, validation_data=test_data, validation_steps=test_steps_per_epoch, use_multiprocessing=True) ``` 结果引发如下错误: ValueError Traceback (most recent call last) <ipython-input-34-ae0a8870fdc1> in <module>() 20 # tf.reset_default_graph() 21 model = Sequential() ---> 22 model.add(resnet) 23 model.add(Dropout(0.5)) 24 model.add(Dense(1, activation='sigmoid')) ...Ignoring many tracing lines... ValueError: Variable bn_conv1/moving_mean/biased already exists, disallowed. Did you mean to set reuse=True in VarScope? Originally defined at: File "xxxx\anaconda3\lib\site-packages\tensorflow\python\framework\ops.py", line 1269, in __init__ self._traceback = _extract_stack() File "xxxx\anaconda3\lib\site-packages\tensorflow\python\framework\ops.py", line 2506, in create_op original_op=self._default_original_op, op_def=op_def) File "xxxx\anaconda3\lib\site-packages\tensorflow\python\framework\op_def_library.py", line 767, in apply_op op_def=op_def) 我按照网上说法在model语句前加了tf.reset_default_graph() ,结果又产生新的error: ValueError: Tensor("conv1_1/kernel:0", shape=(7, 7, 3, 64), dtype=float32_ref) must be from the same graph as Tensor("resnet50/conv1_pad/Pad:0", shape=(?, ?, ?, 3), dtype=float32). 又按照网上说法加了keras.backend.clear_session(),总共加的两句前前后后在很多地方放了测试,结果都会有新的问题: ValueError: Tensor("conv1/kernel:0", shape=(7, 7, 3, 64), dtype=float32_ref) must be from the same graph as Tensor("resnet50/conv1_pad/Pad:0", shape=(?, ?, ?, 3), dtype=float32). 请教大牛究竟该如何彻底解决问题。 问答

没有更多推荐了,返回首页

©️2019 CSDN 皮肤主题: 编程工作室 设计师: CSDN官方博客

分享到微信朋友圈

×

扫一扫,手机浏览