其他
肉眼难辨别的裂纹该怎么检测?
The following article is from 小白学视觉 Author 努比
images = []
for url in tqdm.tqdm(df['content']):
response = requests.get(url)
img = Image.open(BytesIO(response.content))
img = img.resize((224, 224))
numpy_img = img_to_array(img)
img_batch = np.expand_dims(numpy_img, axis=0)
images.append(img_batch.astype('float16'))
images = np.vstack(images)
vgg_conv = vgg16.VGG16(weights='imagenet', include_top=False, input_shape = (224, 224, 3))
for layer in vgg_conv.layers[:-8]:
layer.trainable = False
x = vgg_conv.output
x = GlobalAveragePooling2D()(x)
x = Dense(2, activation="softmax")(x)
model = Model(vgg_conv.input, x)
model.compile(loss = "categorical_crossentropy", optimizer = optimizers.SGD(lr=0.0001, momentum=0.9), metrics=["accuracy"])
def plot_activation(img):
pred = model.predict(img[np.newaxis,:,:,:])
pred_class = np.argmax(pred)
weights = model.layers[-1].get_weights()[0]
class_weights = weights[:, pred_class]
intermediate = Model(model.input,
model.get_layer("block5_conv3").output)
conv_output = intermediate.predict(img[np.newaxis,:,:,:])
conv_output = np.squeeze(conv_output)
h = int(img.shape[0]/conv_output.shape[0])
w = int(img.shape[1]/conv_output.shape[1])
act_maps = sp.ndimage.zoom(conv_output, (h, w, 1), order=1)
out = np.dot(act_maps.reshape((img.shape[0]*img.shape[1],512)),
class_weights).reshape(img.shape[0],img.shape[1])
plt.imshow(img.astype('float32').reshape(img.shape[0],
img.shape[1],3))
plt.imshow(out, cmap='jet', alpha=0.35)
plt.title('Crack' if pred_class == 1 else 'No Crack')
程序员如何避免陷入“内卷”、选择什么技术最有前景,中国开发者现状与技术趋势究竟是什么样?快来参与「2020 中国开发者大调查」,更有丰富奖品送不停!
☞1.6 万亿参数你怕了吗?谷歌大脑语言模型速度是 T5 速度的 7 倍
☞2020 ACM Fellows 名单出炉,13 名华人入选,7 名来自国内!