diff --git a/README.md b/README.md index d4f76a3b54611430afa038f74db7c39d8fe747ad..5eb9ed8fb43f132511e82bd56fa9831eb407c9a8 100644 --- a/README.md +++ b/README.md @@ -69,11 +69,6 @@ cd .. ```bash -# 设置PYTHONPATH环境变量 -export PYTHONPATH=. -# windows下设置环境变量 -SET PYTHONPATH=. - # 预测image_dir指定的单张图像 python3 tools/infer/predict_system.py --image_dir="./doc/imgs/11.jpg" --det_model_dir="./inference/ch_det_mv3_db/" --rec_model_dir="./inference/ch_rec_mv3_crnn/" diff --git a/README_en.md b/README_en.md index c941b67f894a9ee229a43abcadc173fc538b0c7f..c64b65c4cb28d5010d340e5bc1f7605c437a2300 100644 --- a/README_en.md +++ b/README_en.md @@ -69,11 +69,6 @@ The following code implements text detection and recognition inference tandemly. ```bash -# Set PYTHONPATH environment variable -export PYTHONPATH=. -# Setting environment variable in Windows -SET PYTHONPATH=. - # Prediction on a single image by specifying image path to image_dir python3 tools/infer/predict_system.py --image_dir="./doc/imgs/11.jpg" --det_model_dir="./inference/ch_det_mv3_db/" --rec_model_dir="./inference/ch_rec_mv3_crnn/" diff --git a/ppocr/modeling/architectures/det_model.py b/ppocr/modeling/architectures/det_model.py index 5016546ac08d06d361d0352498ac853084e61bca..7ea0949bc80c55724182704616a93b879be92314 100755 --- a/ppocr/modeling/architectures/det_model.py +++ b/ppocr/modeling/architectures/det_model.py @@ -59,16 +59,23 @@ class DetModel(object): return: (image, corresponding label, dataloader) """ image_shape = deepcopy(self.image_shape) + if image_shape[1] % 4 != 0 or image_shape[2] % 4 != 0: + raise Exception("The size of the image must be divisible by 4, " + "received image shape is {}, please reset the " + "Global.image_shape in the yml file".format( + image_shape)) + image = fluid.layers.data( name='image', shape=image_shape, dtype='float32') if mode == "train": if self.algorithm == "EAST": + h, w = int(image_shape[1] // 4), int(image_shape[2] // 4) score = fluid.layers.data( - name='score', shape=[1, 128, 128], dtype='float32') + name='score', shape=[1, h, w], dtype='float32') geo = fluid.layers.data( - name='geo', shape=[9, 128, 128], dtype='float32') + name='geo', shape=[9, h, w], dtype='float32') mask = fluid.layers.data( - name='mask', shape=[1, 128, 128], dtype='float32') + name='mask', shape=[1, h, w], dtype='float32') feed_list = [image, score, geo, mask] labels = {'score': score, 'geo': geo, 'mask': mask} elif self.algorithm == "DB": diff --git a/tools/eval.py b/tools/eval.py index d1762e9294d43a141694d14cca7d401ab134c972..2db6273a7b00ccded42fc876b1bf06dfbfce9a6a 100755 --- a/tools/eval.py +++ b/tools/eval.py @@ -17,6 +17,10 @@ from __future__ import division from __future__ import print_function import os +import sys +__dir__ = os.path.dirname(__file__) +sys.path.append(__dir__) +sys.path.append(os.path.join(__dir__, '..')) def set_paddle_flags(**kwargs): diff --git a/tools/export_model.py b/tools/export_model.py index 555ba7b0e43c0b2479fa8ea92bc1c541f4805269..4415eda84048395da094c0bc6e5685979f94a2e8 100644 --- a/tools/export_model.py +++ b/tools/export_model.py @@ -18,9 +18,9 @@ from __future__ import print_function import os import sys -import time -import multiprocessing -import numpy as np +__dir__ = os.path.dirname(__file__) +sys.path.append(__dir__) +sys.path.append(os.path.join(__dir__, '..')) def set_paddle_flags(**kwargs): diff --git a/tools/infer/predict_det.py b/tools/infer/predict_det.py index 35d8a09dafc3dbaa153609b916bcffec575e9dce..93a21c512d77d495842b5750a034df4d5255acfb 100755 --- a/tools/infer/predict_det.py +++ b/tools/infer/predict_det.py @@ -11,8 +11,13 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. +import os +import sys +__dir__ = os.path.dirname(__file__) +sys.path.append(__dir__) +sys.path.append(os.path.join(__dir__, '../..')) -import utility +import tools.infer.utility as utility from ppocr.utils.utility import initial_logger logger = initial_logger() from ppocr.utils.utility import get_image_file_list diff --git a/tools/infer/predict_rec.py b/tools/infer/predict_rec.py index d47b81afd0f6b44a85135396e9bf0b9bfb029a4f..b96a9fab08395612b100a49ed28fce0941e70ad2 100755 --- a/tools/infer/predict_rec.py +++ b/tools/infer/predict_rec.py @@ -11,8 +11,13 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. +import os +import sys +__dir__ = os.path.dirname(__file__) +sys.path.append(__dir__) +sys.path.append(os.path.join(__dir__, '../..')) -import utility +import tools.infer.utility as utility from ppocr.utils.utility import initial_logger logger = initial_logger() from ppocr.utils.utility import get_image_file_list diff --git a/tools/infer/predict_system.py b/tools/infer/predict_system.py index 1019279a24253d44b7e010adcf286dcd1d58300b..032d094cf4d573b36004e34dc8d40da00013f6b3 100755 --- a/tools/infer/predict_system.py +++ b/tools/infer/predict_system.py @@ -16,12 +16,13 @@ import sys __dir__ = os.path.dirname(__file__) sys.path.append(__dir__) sys.path.append(os.path.join(__dir__, '../..')) -import utility + +import tools.infer.utility as utility from ppocr.utils.utility import initial_logger logger = initial_logger() import cv2 -import predict_det -import predict_rec +import tools.infer.predict_det as predict_det +import tools.infer.predict_rec as predict_rec import copy import numpy as np import math diff --git a/tools/infer_det.py b/tools/infer_det.py index 800067655a1da29f4cd517207db24c2aac15c810..f7dbd8eb1ec6c29b4fc0d098909bbc63beed91d8 100755 --- a/tools/infer_det.py +++ b/tools/infer_det.py @@ -16,14 +16,15 @@ from __future__ import absolute_import from __future__ import division from __future__ import print_function -import os -import sys -import time import numpy as np from copy import deepcopy import json -# from paddle.fluid.contrib.model_stat import summary +import os +import sys +__dir__ = os.path.dirname(__file__) +sys.path.append(__dir__) +sys.path.append(os.path.join(__dir__, '..')) def set_paddle_flags(**kwargs): diff --git a/tools/infer_rec.py b/tools/infer_rec.py index ec64a38bba789029c069b1597a4cde51a382a241..b1ddc8dda198b92414bc7d7a853de78527456e5a 100755 --- a/tools/infer_rec.py +++ b/tools/infer_rec.py @@ -16,10 +16,12 @@ from __future__ import absolute_import from __future__ import division from __future__ import print_function -import os -import time -import multiprocessing import numpy as np +import os +import sys +__dir__ = os.path.dirname(__file__) +sys.path.append(__dir__) +sys.path.append(os.path.join(__dir__, '..')) def set_paddle_flags(**kwargs): @@ -35,10 +37,7 @@ set_paddle_flags( FLAGS_eager_delete_tensor_gb=0, # enable GC to save memory ) -from paddle import fluid - -# from ppocr.utils.utility import load_config, merge_config -import program +import tools.program as program from paddle import fluid from ppocr.utils.utility import initial_logger logger = initial_logger() @@ -47,7 +46,6 @@ from ppocr.utils.save_load import init_model from ppocr.utils.character import CharacterOps from ppocr.utils.utility import create_module from ppocr.utils.utility import get_image_file_list -logger = initial_logger() def main(): diff --git a/tools/train.py b/tools/train.py index 4f69d40f5f19705ce3d75992ee63c188d7fdf944..287ed2059e9393a3fc1758e76b008891939a8424 100755 --- a/tools/train.py +++ b/tools/train.py @@ -18,9 +18,9 @@ from __future__ import print_function import os import sys -import time -import multiprocessing -import numpy as np +__dir__ = os.path.dirname(__file__) +sys.path.append(__dir__) +sys.path.append(os.path.join(__dir__, '..')) def set_paddle_flags(**kwargs):