Loading [MathJax]/jax/output/CommonHTML/config.js
前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >专栏 >Keras_Tutorial_v2a

Keras_Tutorial_v2a

作者头像
列夫托尔斯昊
发布于 2020-08-25 08:31:23
发布于 2020-08-25 08:31:23
93700
代码可运行
举报
文章被收录于专栏:探物及理探物及理
运行总次数:0
代码可运行

Keras tutorial - Emotion Detection in Images of Faces

Welcome to the first assignment of week 2. In this assignment, you will:

  1. Learn to use Keras, a high-level neural networks API (programming framework), written in Python and capable of running on top of several lower-level frameworks including TensorFlow and CNTK.
  2. See how you can in a couple of hours build a deep learning algorithm.
Why are we using Keras?
  • Keras was developed to enable deep learning engineers to build and experiment with different models very quickly.
  • Just as TensorFlow is a higher-level framework than Python, Keras is an even higher-level framework and provides additional abstractions.
  • Being able to go from idea to result with the least possible delay is key to finding good models.
  • However, Keras is more restrictive than the lower-level frameworks, so there are some very complex models that you would still implement in TensorFlow rather than in Keras.
  • That being said, Keras will work fine for many common models.

Updates

If you were working on the notebook before this update...
  • The current notebook is version "v2a".
  • You can find your original work saved in the notebook with the previous version name ("v2").
  • To view the file directory, go to the menu "File->Open", and this will open a new tab that shows the file directory.
List of updates
  • Changed back-story of model to "emotion detection" from "happy house."
  • Cleaned/organized wording of instructions and commentary.
  • Added instructions on how to set input_shape
  • Added explanation of "objects as functions" syntax.
  • Clarified explanation of variable naming convention.
  • Added hints for steps 1,2,3,4

Load packages

  • In this exercise, you'll work on the "Emotion detection" model, which we'll explain below.
  • Let's load the required packages.
代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
import numpy as np
from keras import layers
from keras.layers import Input, Dense, Activation, ZeroPadding2D, BatchNormalization, Flatten, Conv2D
from keras.layers import AveragePooling2D, MaxPooling2D, Dropout, GlobalMaxPooling2D, GlobalAveragePooling2D
from keras.models import Model
from keras.preprocessing import image
from keras.utils import layer_utils
from keras.utils.data_utils import get_file
from keras.applications.imagenet_utils import preprocess_input
import pydot
from IPython.display import SVG
from keras.utils.vis_utils import model_to_dot
from keras.utils import plot_model
from kt_utils import *

import keras.backend as K
K.set_image_data_format('channels_last')
import matplotlib.pyplot as plt
from matplotlib.pyplot import imshow

%matplotlib inline
代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
Using TensorFlow backend.

Note: As you can see, we've imported a lot of functions from Keras. You can use them by calling them directly in your code. Ex: X = Input(...) or X = ZeroPadding2D(...).

In other words, unlike TensorFlow, you don't have to create the graph and then make a separate sess.run() call to evaluate those variables.

1 - Emotion Tracking

  • A nearby community health clinic is helping the local residents monitor their mental health.
  • As part of their study, they are asking volunteers to record their emotions throughout the day.
  • To help the participants more easily track their emotions, you are asked to create an app that will classify their emotions based on some pictures that the volunteers will take of their facial expressions.
  • As a proof-of-concept, you first train your model to detect if someone's emotion is classified as "happy" or "not happy."

To build and train this model, you have gathered pictures of some volunteers in a nearby neighborhood. The dataset is labeled.

style="width:550px;height:250px;">

Run the following code to normalize the dataset and learn about its shapes.

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
X_train_orig, Y_train_orig, X_test_orig, Y_test_orig, classes = load_dataset()

# Normalize image vectors
X_train = X_train_orig/255.
X_test = X_test_orig/255.

# Reshape
Y_train = Y_train_orig.T
Y_test = Y_test_orig.T

print ("number of training examples = " + str(X_train.shape[0]))
print ("number of test examples = " + str(X_test.shape[0]))
print ("X_train shape: " + str(X_train.shape))
print ("Y_train shape: " + str(Y_train.shape))
print ("X_test shape: " + str(X_test.shape))
print ("Y_test shape: " + str(Y_test.shape))
代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
number of training examples = 600
number of test examples = 150
X_train shape: (600, 64, 64, 3)
Y_train shape: (600, 1)
X_test shape: (150, 64, 64, 3)
Y_test shape: (150, 1)

Details of the "Face" dataset:

  • Images are of shape (64,64,3)
  • Training: 600 pictures
  • Test: 150 pictures

2 - Building a model in Keras

Keras is very good for rapid prototyping. In just a short time you will be able to build a model that achieves outstanding results.

Here is an example of a model in Keras:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
def model(input_shape):
    """
    input_shape: The height, width and channels as a tuple.  
        Note that this does not include the 'batch' as a dimension.
        If you have a batch like 'X_train', 
        then you can provide the input_shape using
        X_train.shape[1:]
    """
    
    # Define the input placeholder as a tensor with shape input_shape. Think of this as your input image!
    X_input = Input(input_shape)

    # Zero-Padding: pads the border of X_input with zeroes
    X = ZeroPadding2D((3, 3))(X_input)

    # CONV -> BN -> RELU Block applied to X
    X = Conv2D(32, (7, 7), strides = (1, 1), name = 'conv0')(X)
    X = BatchNormalization(axis = 3, name = 'bn0')(X)
    X = Activation('relu')(X)

    # MAXPOOL
    X = MaxPooling2D((2, 2), name='max_pool')(X)

    # FLATTEN X (means convert it to a vector) + FULLYCONNECTED
    X = Flatten()(X)
    X = Dense(1, activation='sigmoid', name='fc')(X)

    # Create model. This creates your Keras model instance, you'll use this instance to train/test the model.
    model = Model(inputs = X_input, outputs = X, name='HappyModel')
    
    return model
Variable naming convention
  • Note that Keras uses a different convention with variable names than we've previously used with numpy and TensorFlow.
  • Instead of creating unique variable names for each step and each layer, such as X = ... Z1 = ... A1 = ...
  • Keras re-uses and overwrites the same variable at each step: X = ... X = ... X = ...
  • The exception is X_input, which we kept separate since it's needed later.
Objects as functions
  • Notice how there are two pairs of parentheses in each statement. For example: X = ZeroPadding2D((3, 3))(X_input)
  • The first is a constructor call which creates an object (ZeroPadding2D).
  • In Python, objects can be called as functions. Search for 'python object as function and you can read this blog post Python Pandemonium. See the section titled "Objects as functions."
  • The single line is equivalent to this: ZP = ZeroPadding2D((3, 3)) # ZP is an object that can be called as a function X = ZP(X_input)

Exercise: Implement a HappyModel().

  • This assignment is more open-ended than most.
  • Start by implementing a model using the architecture we suggest, and run through the rest of this assignment using that as your initial model. * Later, come back and try out other model architectures.
  • For example, you might take inspiration from the model above, but then vary the network architecture and hyperparameters however you wish.
  • You can also use other functions such as AveragePooling2D(), GlobalMaxPooling2D(), Dropout().

Note: Be careful with your data's shapes. Use what you've learned in the videos to make sure your convolutional, pooling and fully-connected layers are adapted to the volumes you're applying it to.

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
# GRADED FUNCTION: HappyModel

def HappyModel(input_shape):
    """
    Implementation of the HappyModel.
    
    Arguments:
    input_shape -- shape of the images of the dataset
        (height, width, channels) as a tuple.  
        Note that this does not include the 'batch' as a dimension.
        If you have a batch like 'X_train', 
        then you can provide the input_shape using
        X_train.shape[1:]


    Returns:
    model -- a Model() instance in Keras
    
    """
    
    ### START CODE HERE ###
    # Feel free to use the suggested outline in the text above to get started, and run through the whole
    # exercise (including the later portions of this notebook) once. The come back also try out other
    # network architectures as well. 
    X_input = Input(input_shape)
    X = ZeroPadding2D((1,1))(X_input)
    X = Conv2D(32,(3,3),strides=(1,1),name = 'conv0')(X)
    X = BatchNormalization(axis = 3,name = 'bn0')(X)
    X = Activation('relu')(X)
    
    X = MaxPooling2D((2,2),name = 'max_pool')(X)
    X = Flatten()(X)
    Y = Dense(1,activation='sigmoid',name = 'fc')(X)
    
    model = Model(inputs= X_input, outputs = Y, name = 'HappyModel')
    
    
    
    ### END CODE HERE ###
    
    return model

You have now built a function to describe your model. To train and test this model, there are four steps in Keras:

  1. Create the model by calling the function above
  2. Compile the model by calling model.compile(optimizer = "...", loss = "...", metrics = ["accuracy"])
  3. Train the model on train data by calling model.fit(x = ..., y = ..., epochs = ..., batch_size = ...)
  4. Test the model on test data by calling model.evaluate(x = ..., y = ...)

If you want to know more about model.compile(), model.fit(), model.evaluate() and their arguments, refer to the official Keras documentation.

Step 1: create the model.

Hint: The input_shape parameter is a tuple (height, width, channels). It excludes the batch number. Try X_train.shape[1:] as the input_shape.

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
### START CODE HERE ### (1 line)
happyModel = HappyModel(X_train[1,:].shape)
### END CODE HERE ###
Step 2: compile the model

Hint: Optimizers you can try include 'adam', 'sgd' or others. See the documentation for optimizers The "happiness detection" is a binary classification problem. The loss function that you can use is 'binary_cross_entropy'. Note that 'categorical_cross_entropy' won't work with your data set as its formatted, because the data is an array of 0 or 1 rather than two arrays (one for each category). Documentation for losses

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
### START CODE HERE ### (1 line)
happyModel.compile(optimizer="Adam",loss="binary_crossentropy",metrics=["accuracy"])
### END CODE HERE ###
Step 3: train the model

Hint: Use the 'X_train', 'Y_train' variables. Use integers for the epochs and batch_size

Note: If you run fit() again, the model will continue to train with the parameters it has already learned instead of reinitializing them.

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
### START CODE HERE ### (1 line)
happyModel.fit(X_train,Y_train,epochs=40, batch_size=32)
### END CODE HERE ###
代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
Epoch 1/40
600/600 [==============================] - 9s - loss: 0.2501 - acc: 0.9017     
Epoch 2/40
600/600 [==============================] - 8s - loss: 0.1819 - acc: 0.9367     
Epoch 3/40
600/600 [==============================] - 9s - loss: 0.1683 - acc: 0.9300     
Epoch 4/40
600/600 [==============================] - 8s - loss: 0.1163 - acc: 0.9567     
Epoch 5/40
600/600 [==============================] - 9s - loss: 0.0801 - acc: 0.9800     
Epoch 6/40
600/600 [==============================] - 9s - loss: 0.0918 - acc: 0.9550     
Epoch 7/40
600/600 [==============================] - 8s - loss: 0.0586 - acc: 0.9800     
Epoch 8/40
600/600 [==============================] - 8s - loss: 0.0366 - acc: 0.9917     
Epoch 9/40
600/600 [==============================] - 9s - loss: 0.0286 - acc: 0.9900     
Epoch 10/40
600/600 [==============================] - 9s - loss: 0.0254 - acc: 0.9933     
Epoch 11/40
600/600 [==============================] - 9s - loss: 0.0360 - acc: 0.9900     
Epoch 12/40
600/600 [==============================] - 8s - loss: 0.0215 - acc: 0.9950     
Epoch 13/40
600/600 [==============================] - 9s - loss: 0.0196 - acc: 0.9967     
Epoch 14/40
600/600 [==============================] - 9s - loss: 0.0385 - acc: 0.9833     
Epoch 15/40
600/600 [==============================] - 9s - loss: 0.0170 - acc: 0.9967     
Epoch 16/40
600/600 [==============================] - 9s - loss: 0.0162 - acc: 0.9933     
Epoch 17/40
600/600 [==============================] - 9s - loss: 0.0103 - acc: 0.9983     
Epoch 18/40
600/600 [==============================] - 9s - loss: 0.0111 - acc: 0.9983     
Epoch 19/40
600/600 [==============================] - 9s - loss: 0.0100 - acc: 0.9967     
Epoch 20/40
600/600 [==============================] - 9s - loss: 0.0118 - acc: 0.9983     
Epoch 21/40
600/600 [==============================] - 9s - loss: 0.0086 - acc: 0.9983     
Epoch 22/40
600/600 [==============================] - 9s - loss: 0.0099 - acc: 0.9983     
Epoch 23/40
600/600 [==============================] - 9s - loss: 0.0200 - acc: 0.9917     
Epoch 24/40
600/600 [==============================] - 9s - loss: 0.0099 - acc: 1.0000     
Epoch 25/40
600/600 [==============================] - 9s - loss: 0.0087 - acc: 0.9983     
Epoch 26/40
600/600 [==============================] - 9s - loss: 0.0095 - acc: 0.9967     
Epoch 27/40
600/600 [==============================] - 9s - loss: 0.0075 - acc: 1.0000     
Epoch 28/40
600/600 [==============================] - 9s - loss: 0.0072 - acc: 1.0000     
Epoch 29/40
600/600 [==============================] - 9s - loss: 0.0076 - acc: 0.9983     
Epoch 30/40
600/600 [==============================] - 9s - loss: 0.0052 - acc: 0.9983     
Epoch 31/40
600/600 [==============================] - 9s - loss: 0.0058 - acc: 0.9983     
Epoch 32/40
600/600 [==============================] - 8s - loss: 0.0074 - acc: 0.9967     
Epoch 33/40
600/600 [==============================] - 9s - loss: 0.0044 - acc: 1.0000     
Epoch 34/40
600/600 [==============================] - 8s - loss: 0.0054 - acc: 0.9983     
Epoch 35/40
600/600 [==============================] - 8s - loss: 0.0159 - acc: 0.9933     
Epoch 36/40
600/600 [==============================] - 8s - loss: 0.0149 - acc: 0.9950     
Epoch 37/40
600/600 [==============================] - 8s - loss: 0.0116 - acc: 0.9967     
Epoch 38/40
600/600 [==============================] - 8s - loss: 0.0045 - acc: 1.0000     
Epoch 39/40
600/600 [==============================] - 8s - loss: 0.0064 - acc: 0.9967     
Epoch 40/40
600/600 [==============================] - 8s - loss: 0.0034 - acc: 1.0000     





<keras.callbacks.History at 0x7f43b4792f28>
Step 4: evaluate model

Hint: Use the 'X_test' and 'Y_test' variables to evaluate the model's performance.

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
### START CODE HERE ### (1 line)
preds = happyModel.evaluate(X_test,Y_test)
### END CODE HERE ###
print()
print ("Loss = " + str(preds[0]))
print ("Test Accuracy = " + str(preds[1]))
代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
150/150 [==============================] - 1s     

Loss = 0.0785783381263
Test Accuracy = 0.953333337307
Expected performance

If your happyModel() function worked, its accuracy should be better than random guessing (50% accuracy).

To give you a point of comparison, our model gets around 95% test accuracy in 40 epochs (and 99% train accuracy) with a mini batch size of 16 and "adam" optimizer.

Tips for improving your model

If you have not yet achieved a very good accuracy (>= 80%), here are some things tips:

  • Use blocks of CONV->BATCHNORM->RELU such as: python X = Conv2D(32, (3, 3), strides = (1, 1), name = 'conv0')(X) X = BatchNormalization(axis = 3, name = 'bn0')(X) X = Activation('relu')(X) until your height and width dimensions are quite low and your number of channels quite large (≈32 for example). You can then flatten the volume and use a fully-connected layer.
  • Use MAXPOOL after such blocks. It will help you lower the dimension in height and width.
  • Change your optimizer. We find 'adam' works well.
  • If you get memory issues, lower your batch_size (e.g. 12 )
  • Run more epochs until you see the train accuracy no longer improves.

Note: If you perform hyperparameter tuning on your model, the test set actually becomes a dev set, and your model might end up overfitting to the test (dev) set. Normally, you'll want separate dev and test sets. The dev set is used for parameter tuning, and the test set is used once to estimate the model's performance in production.

3 - Conclusion

Congratulations, you have created a proof of concept for "happiness detection"!

Key Points to remember

  • Keras is a tool we recommend for rapid prototyping. It allows you to quickly try out different model architectures.
  • Remember The four steps in Keras:
  1. Create
  2. Compile
  3. Fit/Train
  4. Evaluate/Test

4 - Test with your own image (Optional)

Congratulations on finishing this assignment. You can now take a picture of your face and see if it can classify whether your expression is "happy" or "not happy". To do that:

  1. Click on "File" in the upper bar of this notebook, then click "Open" to go on your Coursera Hub.
  2. Add your image to this Jupyter Notebook's directory, in the "images" folder
  3. Write your image's name in the following code
  4. Run the code and check if the algorithm is right (0 is not happy, 1 is happy)!

The training/test sets were quite similar; for example, all the pictures were taken against the same background (since a front door camera is always mounted in the same position). This makes the problem easier, but a model trained on this data may or may not work on your own data. But feel free to give it a try!

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
### START CODE HERE ###
img_path = 'images/my_image.jpg'
img_path = 'images/2020-7-9 下午12.50拍摄的照片.jpg'
### END CODE HERE ###
img = image.load_img(img_path, target_size=(64, 64))
imshow(img)

x = image.img_to_array(img)
x = np.expand_dims(x, axis=0)
x = preprocess_input(x)

print(happyModel.predict(x))
代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
[[ 1.]]

5 - Other useful functions in Keras (Optional)

Two other basic features of Keras that you'll find useful are:

  • model.summary(): prints the details of your layers in a table with the sizes of its inputs/outputs
  • plot_model(): plots your graph in a nice layout. You can even save it as ".png" using SVG() if you'd like to share it on social media ;). It is saved in "File" then "Open..." in the upper bar of the notebook.

Run the following code.

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
happyModel.summary()
代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
_________________________________________________________________
Layer (type)                 Output Shape              Param #   
=================================================================
input_4 (InputLayer)         (None, 64, 64, 3)         0         
_________________________________________________________________
zero_padding2d_4 (ZeroPaddin (None, 66, 66, 3)         0         
_________________________________________________________________
conv0 (Conv2D)               (None, 64, 64, 32)        896       
_________________________________________________________________
bn0 (BatchNormalization)     (None, 64, 64, 32)        128       
_________________________________________________________________
activation_4 (Activation)    (None, 64, 64, 32)        0         
_________________________________________________________________
max_pool (MaxPooling2D)      (None, 32, 32, 32)        0         
_________________________________________________________________
flatten_4 (Flatten)          (None, 32768)             0         
_________________________________________________________________
fc (Dense)                   (None, 1)                 32769     
=================================================================
Total params: 33,793
Trainable params: 33,729
Non-trainable params: 64
_________________________________________________________________
代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
plot_model(happyModel, to_file='HappyModel.png')
SVG(model_to_dot(happyModel).create(prog='dot', format='svg'))
代码语言:javascript
代码运行次数:0
运行
复制
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2020-07-09 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
暂无评论
推荐阅读
编辑精选文章
换一批
WordPress 支持 WebP格式图片上传方法
WebP(发音:weppy)是一种同时提供了有损压缩与无损压缩(可逆压缩)的图片文件格式,派生自影像编码格式VP8,被认为是WebM多媒体格式的姊妹项目,是由Google在购买On2 Technologies后发展出来,以BSD授权条款发布。
阳光岛主
2019/12/30
2.2K0
WordPress 支持 WebP格式图片上传方法
为你的网站用上 WebP 图片吧
之前写了一篇文章:jpg、gif、png和svg用于web上,我们该如何选择最合适的图像格式,介绍了这几种图片格式的特点,以及如何为网站选择合适的图片,然后评论区有位大佬让我补充下 WebP 格式,于是乎它来了。
用户4456933
2021/06/01
1.5K0
为你的网站用上 WebP 图片吧
悟空活动中台 - 基于 WebP 的图片高性能加载方案
移动端网页的加载速度对用户体验极为重要,是影响页面转化率的关键因素,H5 活动页往往使用大量的图片素材来丰富活动效果,素材加载的快慢会对用户感知造成重要的影响。
2020labs小助手
2020/08/17
1.5K0
​PNG图片压缩对比分析
随着版本的迭代,业务的增加,QQ音乐apk的大小已经超过25M,其中res目录占用的大小超过5.5M,所以提出了对安装包进行瘦身的技术需求。
QQ音乐技术团队
2018/02/01
10.2K0
​PNG图片压缩对比分析
听陈嘉讲那关于WebP的故事
你知道是什么是WebP吗? 它是Google出品的新图像格式,这是一个Web开发者需要扩充的新知。成都办公室之前来了一个UI开发人员,面试的时候,用自己开发JavaScript体感游戏震惊了大家。 他叫陈嘉,请看他为大家带来的关于WebP的介绍。 WEBP是什么呢? WEBP 是google推出的意图改变web图片JPG、PNG、GIF三分天下局势的一种图片格式。它不仅支持无损或有损压缩、alpha通道,还支持动画演示。在同画质的情况下,webp格式图片占用体积相较于jpg图片大约减少40%,相较于无损p
ThoughtWorks
2018/04/18
9400
听陈嘉讲那关于WebP的故事
关于webp图片格式初探
前言 不管是 PC 还是移动端,图片一直是流量大头,以苹果公司 Retina 产品为代表的高 PPI 屏对图片的质量提出了更高的要求,如何保证在图片的精细度不降低的前提下缩小图片体积,成为了一个有价值且值得探索的事情。 但如今对于 JPEG、PNG 和 GIF 这些图片格式的优化几乎已经达到了极致, 若想改变现状开辟新局面,便要有釜底抽薪的胆量和气魄,而 Google 给了我们一个新选择:WebP。 对 WebP 的研究缘起于手机 QQ 原创表情商城,由于表情包体积较大,在 2G/3G 的网络环境
xiangzhihong
2018/02/01
5.5K0
关于webp图片格式初探
WordPress 5.8 将内置 WebP 图片格式支持
WebP 是 Google 早在 2010 年就提出的一种新的图片压缩格式,相比 JPEG 和 PNG 格式的图片,文件大小平均小了 30% 左右,从而使得网站的速度更快,使用的带宽也更少,根据 caniuse 网站的统计,目前所有现代浏览器基本都支持 WebP 了:
Denis
2023/04/13
6640
WordPress 5.8 将内置 WebP 图片格式支持
CentOS系统下多种图片压缩方案
在文章《使用TinyPNG来优化您的网站图片》介绍过TinyPNG提供的压缩服务,效果非常棒。ImgURL 图床也是使用TinyPNG来提供图片压缩,不过TinyPNG有免费次数限制。于是xiaoz寻找了Linux系统下的其它图片压缩方案,希望后期能够用到。
星哥玩云
2022/08/13
5660
CentOS系统下多种图片压缩方案
WebP为何那么受欢迎?
WebP格式,谷歌(google)开发的一种旨在加快图片加载速度的图片格式。图片压缩体积大约只有JPEG的2/3,并能节省大量的服务器带宽资源和数据空间。Facebook Ebay等知名网站已经开始测试并使用WebP格式。 WebP 在各大互联网公司已经使用得很多了,国外的有 Google(自家的东西肯定要用啦,Chrome Store 甚至已全站使用 WebP)、Facebook 和 ebay,国内的有淘宝、腾讯和美团等。 Webp优势: 更优的图像数据压缩算法 更小的图片体积 肉眼识别无差异的图像质量
神无月
2018/06/25
4.7K0
【学习图片】08:WebP
WebP的有损压缩算法基于VP8视频编解码器用于压缩视频关键帧的方法。从高层次来看,它类似于JPEG编码:WebP以“块”为单位操作,而不是单个像素,并且具有类似亮度和色度之间的分割。WebP的亮度块为16x16,色度块为8x8,并且这些“macroblocks”进一步细分为4x4子块。
前端小智@大迁世界
2023/03/01
1.1K0
【学习图片】08:WebP
使用WebP-Server-Go无缝转换图片为Google的webp格式让你网站访问加载速度飞起来
[TOC] 0x00 快速入门 WebP 介绍 什么是 WebP? WebP是由Google推出的一种全新图片文件格式,也是Telegram Stickers 主力使用的文件格式,可为 Web 上的图
全栈工程师修炼指南
2022/09/29
1.9K0
使用WebP-Server-Go无缝转换图片为Google的webp格式让你网站访问加载速度飞起来
如何编辑webp图片?
2023/10/18
7790
如何编辑webp图片?
WordPress不支持svg/ico/webp上传怎么办?
小狐狸教你不用WordPress插件即可搞定该问题,其实【关键词】早也分享过《WordPress怎么上传SVG图片到媒体库之Safe SVG插件》,我们还是在现有WordPress模板函数文件functions.php中,添加以下代码即可:
小狐狸说事
2023/11/17
4850
App极限瘦身: png 打包前自动化转换 webp
改不完的 Bug,写不完的矫情。公众号 杨正友 现在专注移动基础平台开发 ,涵盖音视频, APM和信息安全等各个知识领域;只做全网最 Geek 的公众号,欢迎您的关注!精彩内容不容错过~ 前言 大家都
小木箱
2020/11/24
2.4K0
位图/矢量图/GIF/PNG/JPEG/WEBP一网打尽
大家好,我是「柒八九」。一个「专注于前端开发技术/Rust及AI应用知识分享」的Coder。
前端柒八九
2024/03/07
6230
位图/矢量图/GIF/PNG/JPEG/WEBP一网打尽
让typecho支持webp格式的图片,告别阿里云oss和腾讯云cos被恶意刷流量的风险
还记得当初使用WordPress博客系统的时候,基本上写文章都喜欢用webp格式的图片
imzql
2021/12/28
2.7K1
让typecho支持webp格式的图片,告别阿里云oss和腾讯云cos被恶意刷流量的风险
3分钟阅读 | webp画质感人,尺寸嫉妒,前后端程序员都来看!
使用ImageMagick、cwebp和OSX,我们可以将任何图像格式转换为WebP。今天我们将把这个 YellowFlower.jpg 文件转换成一个 YellowFlower.webp 文件,并在没有太大质量损失的情况下,缩减文件大小的三分之一。
程序员小助手
2020/06/10
1K0
3分钟阅读 | webp画质感人,尺寸嫉妒,前后端程序员都来看!
使用WebP图片加快您网站访问速度
WebP是由Google在2010年基于VP8视频格式开发的开放图像格式。从那时起,使用WebP格式的网站和移动应用程序的数量迅速增长。Google Chrome和Opera本身都支持WebP格式,这些浏览器占网络流量的大约74%,因此如果网站使用WebP格式的图像,用户可以更快地访问网站。
圣人惠好可爱
2018/08/09
5.6K0
扒一扒“WEBP格式”的图片
HTML5学堂:谷歌于2010年推出的新一代图片格式 —— WEBP,随着移动互联网的发展,WEBP格式在2015年逐渐的开始被大公司部分采用。本文主要除了比较WEBP与JPG等传统格式的图片之外,还介绍了如何转换WEBP格式图片以及具体开发时的用法。 使用WEBP图片的目的 保证图片质量的前提下缩小图片体积。JPEG、PNG以及GIF这些格式的图片已经没有太大的优化空间。但是,WebP图片格式给图片优化提供了另一种可能 图片压缩 无损压缩的图片格式 TIFF;GIF;RAW;PCX;TAG;PNG;BMP
HTML5学堂
2018/03/13
3.2K0
扒一扒“WEBP格式”的图片
GIF/PNG/JPG和WEBP/base64/apng图片优点和缺点整理
阅读目录 GIF(Graphics Interchange Format) PNG(Portable Network Graphics) JPG(Joint Photographic Experts Group) base64 APNG   GIF/PNG/JPG/WEBP/APNG都是属于位图(位图 ,务必区别于矢量图);   GIF/PNG和JPG这三种格式的图片被广泛应用在现今的互联网中,gif曾在过去互联网初期慢速的情况下几乎是做到了大一统的地位,而现如今随着互联网技术应用和硬件条件的提高,png和
逸鹏
2018/04/11
3.4K0
GIF/PNG/JPG和WEBP/base64/apng图片优点和缺点整理
推荐阅读
相关推荐
WordPress 支持 WebP格式图片上传方法
更多 >
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档
本文部分代码块支持一键运行,欢迎体验
本文部分代码块支持一键运行,欢迎体验