40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
|
# File 'lib/transformers/image_processing_base.rb', line 40
def self.get_image_processor_dict(
pretrained_model_name_or_path, **kwargs
)
cache_dir = kwargs.delete(:cache_dir)
force_download = kwargs.delete(:force_download) { false }
resume_download = kwargs.delete(:resume_download)
proxies = kwargs.delete(:proxies)
token = kwargs.delete(:token)
_use_auth_token = kwargs.delete(:use_auth_token)
local_files_only = kwargs.delete(:local_files_only) { false }
revision = kwargs.delete(:revision)
subfolder = kwargs.delete(:subfolder) { "" }
from_pipeline = kwargs.delete(:_from_pipeline)
from_auto_class = kwargs.delete(:_from_auto) { false }
user_agent = {file_type: "image processor", from_auto_class: from_auto_class}
if !from_pipeline.nil?
user_agent[:using_pipeline] = from_pipeline
end
if Utils::Hub.is_offline_mode && !local_files_only
Transformers.logger.info("Offline mode: forcing local_files_only: true")
local_files_only = true
end
pretrained_model_name_or_path = pretrained_model_name_or_path.to_s
is_local = Dir.exist?(pretrained_model_name_or_path)
if Dir.exist?(pretrained_model_name_or_path)
image_processor_file = File.join(pretrained_model_name_or_path, IMAGE_PROCESSOR_NAME)
end
if File.exist?(pretrained_model_name_or_path)
resolved_image_processor_file = pretrained_model_name_or_path
is_local = true
elsif Utils::Hub.is_remote_url(pretrained_model_name_or_path)
raise Todo
else
image_processor_file = IMAGE_PROCESSOR_NAME
begin
resolved_image_processor_file = Utils::Hub.cached_file(
pretrained_model_name_or_path,
image_processor_file,
cache_dir: cache_dir,
force_download: force_download,
proxies: proxies,
resume_download: resume_download,
local_files_only: local_files_only,
token: token,
user_agent: user_agent,
revision: revision,
subfolder: subfolder
)
rescue EnvironmentError
raise
rescue
raise EnvironmentError,
"Can't load image processor for '#{pretrained_model_name_or_path}'. If you were trying to load" +
" it from 'https://huggingface.co/models', make sure you don't have a local directory with the" +
" same name. Otherwise, make sure '#{pretrained_model_name_or_path}' is the correct path to a" +
" directory containing a #{IMAGE_PROCESSOR_NAME} file"
end
end
begin
image_processor_dict = JSON.load_file(resolved_image_processor_file).transform_keys(&:to_sym)
rescue JSON::ParserError
raise EnvironmentError,
"It looks like the config file at '#{resolved_image_processor_file}' is not a valid JSON file."
end
if is_local
Transformers.logger.info("loading configuration file #{resolved_image_processor_file}")
else
Transformers.logger.info(
"loading configuration file #{image_processor_file} from cache at #{resolved_image_processor_file}"
)
end
if !is_local
if image_processor_dict.include?("auto_map")
raise Todo
end
if image_processor_dict.include?("custom_pipelines")
raise Todo
end
end
[image_processor_dict, kwargs]
end
|