diff --git a/image_classification/README.md b/image_classification/README.md index 94a0a1b70e9b31e7247eeb2765dc000cb6c19ea9..37aa1f06a9484e2901d80b4aaba6054db923485d 100644 --- a/image_classification/README.md +++ b/image_classification/README.md @@ -221,3 +221,18 @@ for file_name, result in zip(file_list, lab): ``` 首先从文件中加载训练好的模型(代码里以第10轮迭代的结果为例),然后读取`image_list_file`中的图像。`image_list_file`是一个文本文件,每一行为一个图像路径。代码使用`paddle.infer`判断`image_list_file`中每个图像的类别,并进行输出。 + +## 使用预训练模型 +为方便进行测试和fine-tuning,我们提供了一些对应于示例中模型配置的预训练模型,目前包括在ImageNet 1000类上训练的ResNet50、ResNet101和Vgg16,请使用`models`目录下的脚本`model_download.sh`进行模型下载,如下载ResNet50可进入`models`目录并执行"`sh model_download.sh ResNet50`",完成后同目录下的`Paddle_ResNet50.tar.gz`即是训练好的模型,可以在代码中使用如下两种方式进行加载模: + +```python +parameters = paddle.parameters.Parameters.from_tar(gzip.open('Paddle_ResNet50.tar.gz', 'r')) +``` + +```python +parameters = paddle.parameters.create(cost) +parameters.init_from_tar(gzip.open('Paddle_ResNet50.tar.gz', 'r')) +``` + +### 注意事项 +模型压缩包中所含各文件的文件名对应了和模型配置中的参数名一一对应,是加载模型参数的依据。我们提供的预训练模型均使用了示例代码中的配置,如需修改网络配置,请多加注意,需要保证网络配置中的参数名和压缩包中的文件名能够正确对应。 diff --git a/image_classification/index.html b/image_classification/index.html new file mode 100644 index 0000000000000000000000000000000000000000..33e55cebd7e939ad66d8cb4b8b2b1168c338e9ed --- /dev/null +++ b/image_classification/index.html @@ -0,0 +1,302 @@ + + + + + + + + + + + + + + + + + +
+
+ + + + + + + diff --git a/image_classification/models/model_download.sh b/image_classification/models/model_download.sh new file mode 100644 index 0000000000000000000000000000000000000000..2a73c56ec5b73b33bf6a94ac63e5a2dee387b4a9 --- /dev/null +++ b/image_classification/models/model_download.sh @@ -0,0 +1,55 @@ +#! /usr/bin/env bash + +function download() { + URL=$1 + MD5=$2 + TARGET=$3 + + if [ -e $TARGET ]; then + md5_result=`md5sum $TARGET | awk -F[' '] '{print $1}'` + if [ $MD5 == $md5_result ]; then + echo "$TARGET already exists, download skipped." + return 0 + fi + fi + + wget -c $URL -O "$TARGET" + if [ $? -ne 0 ]; then + return 1 + fi + + md5_result=`md5sum $TARGET | awk -F[' '] '{print $1}'` + if [ ! $MD5 == $md5_result ]; then + return 1 + fi +} + +case "$1" in + "ResNet50") + URL="http://cloud.dlnel.org/filepub/?uuid=f63f237a-698e-4a22-9782-baf5bb183019" + MD5="eb4d7b5962c9954340207788af0d6967" + ;; + "ResNet101") + URL="http://cloud.dlnel.org/filepub/?uuid=3d5fb996-83d0-4745-8adc-13ee960fc55c" + MD5="7e71f24998aa8e434fa164a7c4fc9c02" + ;; + "Vgg16") + URL="http://cloud.dlnel.org/filepub/?uuid=aa0e397e-474a-4cc1-bd8f-65a214039c2e" + MD5="e73dc42507e6acd3a8b8087f66a9f395" + ;; + *) + echo "The "$1" model is not provided currently." + exit 1 + ;; +esac +TARGET="Paddle_"$1".tar.gz" + +echo "Download "$1" model ..." +download $URL $MD5 $TARGET +if [ $? -ne 0 ]; then + echo "Fail to download the model!" + exit 1 +fi + + +exit 0