我运行了这段代码,但是没有用。这不是错误。在Jupyter笔记本中,它仍在运行(标记为[*]中)
这是我的jupyter笔记本
_________________________________
In [*]: model.fit(
img_vector, y,
batch_size=128,
epochs=10,
verbose=2
)
___________________________
WARNING:tensorflow:From C:\Users\il357\Anaconda3\envs\mlbook\lib\site-packages\tensorflow\python\ops\math_ops.py:3066: to_int32 (from tensorflow.python.ops.math_ops) is deprecated and will be removed in a future version.
Instructions for updating:
Use tf.cast instead.
Epoch 1/10
第1/10章已被标记,仅此而已。 我将写下以前的代码。我将省略导入代码。 (这是Deeplearning Cookbook的代码。您可以在github中找到它。 并且此代码正在我的笔记本电脑上运行。)
# The number of image files is very large.. I think this maybe is the problem.
pet_images_fn = [fn for fn in os.listdir('pet_images') if fn.endswith('.jpg')]
# make image vector
labels = []
idx_to_labels = []
label_to_idx = {}
for fn in pet_images_fn:
label, _ = fn.rsplit('_', 1)
if not label in label_to_idx:
label_to_idx[label] = len(idx_to_labels)
idx_to_labels.append(label)
labels.append(label_to_idx[label])
len(idx_to_labels)
def fetch_pet(pet):
img = image.load_img('pet_images/' + pet, target_size=(299, 299))
return image.img_to_array(img)
img_vector = np.asarray([fetch_pet(pet) for pet in pet_images_fn])
# make model with InceptionV3
base_model = InceptionV3(weights='imagenet', include_top=False, input_shape=(299, 299, 3))
for layer in base_model.layers:
layer.trainable = False
pool_2d = GlobalAveragePooling2D(name='pool_2d')(base_model.output)
dense = Dense(1024, name='dense', activation='relu')(pool_2d)
predictions = Dense(len(idx_to_labels), activation='softmax')(dense)
model = Model(inputs=base_model.input, outputs=predictions)
model.compile(optimizer='rmsprop', loss='categorical_crossentropy', metrics=['accuracy'])
# set label to one hot encoding
y = np.zeros((len(labels), len(idx_to_labels)))
for idx, label in enumerate(labels):
y[idx][label] = 1
model.fit(
img_vector, y,
batch_size=128,
epochs=15,
verbose=2
)
答案 0 :(得分:0)
verbose=2
中的model.fit
表示仅在纪元完成后才打印一行,如果您需要设置进度条verbose=1
。