zachwormgoor@gmail.com commited on
Commit
7cafc37
1 Parent(s): 7da8f80

raw kaggle backup

Browse files
kaggle code backup - stock photo recognizer.txt ADDED
@@ -0,0 +1,758 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ Stock photo retriever
3
+
4
+ The goal of this project was to experiment and learn the first lesson of fast.ai, as well as simple data mining. The topic chosen was to be able to tell if a photo was a "stock" photo, more specifically product photos, versus an amateur item photo. This could have applications in determining information about an article or webpage from the types of images it contains.
5
+
6
+ This topic was chosen as an example of something expected to be more difficult than the basic provided examples (is this a bird? is this a cat?), since stock vs. amateur photo differences are as much about the focus, lighting, contrast, etc. as they are about the subject. We can explore whether any of the image models can distinguish these more qualitative aspects of images rather than the typical contained objects, and we can try to get a feel for how much training data might be required to get any amount of accuracy with this technique.
7
+
8
+ First, Craigslist was chosen to get examples of amateur photos as a way of exploring data mining (rather than using the DDG search in the example from fast.ai). This proved to have some interesting challenges. In the last couple years Craigslist appears to have changed their website to dynamically load content only when the page is visibly rendered (perhaps to save bandwidth, or perhaps to mitigate bots), and some online examples of scraping appear to predate this change. So techniques that closely mimic how a human would use a browser were needed, rather than simply making html requests for a page.
9
+
10
+ Selenium was used to scrape the page, it is not expected that this would work through online execution such as Kaggle, so the following code would have to be run locally.
11
+
12
+ # Note: The following probably won't run on an online hosted Jupyter notebook,
13
+ # you'll have to copy the code and run locally.
14
+
15
+ import selenium.webdriver
16
+ from selenium.webdriver.common.by import By
17
+
18
+ def get_first_page_of_images_from_cragslist(craigslist_url):
19
+ # Load page we want to scrape
20
+ driver = selenium.webdriver.Firefox()
21
+ driver.get(craigslist_url) # various stuff in Virginia
22
+
23
+ # Function to scroll to the bottom of a Craigslist page
24
+ def scroll_for_a_while():
25
+ last_height = driver.execute_script("return document.body.scrollHeight")
26
+ outer_frame = driver.find_element(By.CLASS_NAME, "cl-search-results")
27
+ page_loc = last_height
28
+ for i in range(18):
29
+ print("page down")
30
+ driver.execute_script("window.scrollByPages(1);") # firefox only
31
+ time.sleep(.2) # .01 seems to be too fast...window size, PC speed, and internet speed would all affect what speeds work here.
32
+
33
+
34
+ # Scroll and then retrieve page source
35
+
36
+ # Need to wait till page is completely loaded, subsequent retrievals fail otherwise.
37
+ # proper solution is this: https://stackoverflow.com/a/26567563
38
+ # but would have to refactor away from BeautifulSoup.
39
+ # for expediency, just doing a hard wait.
40
+ print("loaded page, but waiting several seconds for page to load...")
41
+ import time
42
+ from threading import Thread
43
+ time.sleep(7)
44
+ print("scrolling to bottom")
45
+ scroll_for_a_while()
46
+ print("parsing page")
47
+ page_text = driver.page_source
48
+
49
+ # Parse page
50
+ # Credit to Riley Predum's Craigslist scraping example, portions taken from it:
51
+ # https://github.com/rileypredum/East-Bay-Housing-Web-Scrape/blob/master/EB_Apt_Prices_Final.ipynb
52
+
53
+ # Note that this could be done with Selenium calls instead.
54
+ from bs4 import BeautifulSoup
55
+ html_soup = BeautifulSoup(page_text, 'html.parser')
56
+
57
+ posts = html_soup.find_all('li', class_= 'cl-search-result cl-search-view-mode-gallery')
58
+ print(type(posts)) #to double check that I got a ResultSet
59
+ print(len(posts)) #to double check I got 120 (elements/page)
60
+
61
+ # Examples of scraping some bits of data to verify operation. Not used at present.
62
+ # Retrieve the first post
63
+ post_one = posts[0]
64
+ imageUrl = post_one.img['src']
65
+
66
+ # Price of the first post
67
+ post_one_price = post_one.find('span', class_= 'priceinfo').text
68
+ post_one_price.strip()
69
+
70
+ # Time / date, meta data
71
+ post_one_time = post_one.find('div', class_= 'meta').text
72
+ #post_one_datetime = post_one_time['datetime']
73
+
74
+ # Title
75
+ post_one_title = post_one['title']
76
+ post_one_link = post_one.a['href']
77
+
78
+ # Finally, retrieve all of the post imgs and aggregate into list:
79
+ def get_img_url_from_post(post):
80
+ return post.img['src']
81
+
82
+ # Should be 120 URLs of imgs in this list:
83
+ post_img_urls = map(get_img_url_from_post, posts)
84
+
85
+ driver.close() # don't open multiple browsers with multiple calls
86
+ return post_img_urls
87
+
88
+
89
+ amateur_photos_virginia = get_first_page_of_images_from_cragslist("https://blacksburg.craigslist.org/search/sss?hasPic=1")
90
+ amateur_photos_oregon = get_first_page_of_images_from_cragslist("https://corvallis.craigslist.org/search/sss?hasPic=1")
91
+ amateur_photos_pennsylvania = get_first_page_of_images_from_cragslist("https://scranton.craigslist.org/search/sss?hasPic=1")
92
+
93
+ # "https://sfbay.craigslist.org/search/eby/apa?hasPic=1&availabilityMode=0") # rental properties
94
+
95
+ print("\r\n# Virginia Craigslist photos:")
96
+ print("amateur_photos_virginia = ['")
97
+ print(*list(amateur_photos_virginia), sep="',\r\n '") # if this throws an exception, probably the scrolling did not work to get the page to load all the images...try slowing down the scrolling.
98
+ print("']")
99
+ print("\r\n# Oregon Craigslist photos:")
100
+ print("amateur_photos_oregon = ['")
101
+ print(*list(amateur_photos_oregon), sep="',\r\n '")
102
+ print("']")
103
+ print("\r\n# Pennsylvania Craigslist photos:")
104
+ print("amateur_photos_pennsylvania = ['")
105
+ print(*list(amateur_photos_pennsylvania), sep="',\r\n '")
106
+ print("']")
107
+
108
+ After executing the above, we have a list of amateur photos. Since it must be run locally, here is the list copied in and with newlines inserted, for use by the subsequent learning steps. Note that this list will go stale as Craigslist posts expire, and would need to be refreshed every few weeks.
109
+
110
+ # https://blacksburg.craigslist.org/search/sss?hasPic=1
111
+ # Virginia Craigslist photos:
112
+ amateur_photos_virginia = [
113
+ 'https://images.craigslist.org/00J0J_eNltABqMNjh_0yc0kd_300x300.jpg',
114
+ 'https://images.craigslist.org/00808_3AVp4eb0ahOz_0iZ0hS_300x300.jpg',
115
+ 'https://images.craigslist.org/00000_hFkdTLJCApg_0t20CI_300x300.jpg',
116
+ 'https://images.craigslist.org/00V0V_737IPDzTIXc_0t20CI_300x300.jpg',
117
+ 'https://images.craigslist.org/00F0F_6FXwhX8nR6V_0CI0t2_300x300.jpg',
118
+ 'https://images.craigslist.org/00m0m_eLQ0BD0E4nZ_0t20CI_300x300.jpg',
119
+ 'https://images.craigslist.org/00101_9dGjak78lCu_0t20CI_300x300.jpg',
120
+ 'https://images.craigslist.org/00d0d_j156UkKlthp_0t20CI_300x300.jpg',
121
+ 'https://images.craigslist.org/01010_25iCkwdZQTZ_0BF0t2_300x300.jpg',
122
+ 'https://images.craigslist.org/00S0S_hVgyYCu1QdZ_0t20CI_300x300.jpg',
123
+ 'https://images.craigslist.org/00z0z_dTeP066NYtc_0t20CI_300x300.jpg',
124
+ 'https://images.craigslist.org/00505_kiOKla8x5T5_0t20CI_300x300.jpg',
125
+ 'https://images.craigslist.org/00U0U_gqwRfvUHeJ5_0CI0t2_300x300.jpg',
126
+ 'https://images.craigslist.org/00U0U_eYU3NulkbVqz_0t20CI_300x300.jpg',
127
+ 'https://images.craigslist.org/01717_cYwoEmmdfRWz_0t20CI_300x300.jpg',
128
+ 'https://images.craigslist.org/00L0L_fUBCwD4lHuvz_0iv0t2_300x300.jpg',
129
+ 'https://images.craigslist.org/00707_dqt587w8YeCz_0t20CI_300x300.jpg',
130
+ 'https://images.craigslist.org/00l0l_lVmhrsldgygz_0t20CI_300x300.jpg',
131
+ 'https://images.craigslist.org/00101_2m9gJ6HBa6d_0ww0oo_300x300.jpg',
132
+ 'https://images.craigslist.org/00G0G_2govN4YFO98_0CI0lM_300x300.jpg',
133
+ 'https://images.craigslist.org/00i0i_hyQh9AVs7O2_0no0t2_300x300.jpg',
134
+ 'https://images.craigslist.org/01212_4oA8YUbZMjv_08l06P_300x300.jpg',
135
+ 'https://images.craigslist.org/00W0W_gwQD25uHvTp_09J07k_300x300.jpg',
136
+ 'https://images.craigslist.org/00j0j_bst3muvvtQT_0gl0t2_300x300.jpg',
137
+ 'https://images.craigslist.org/00k0k_6Ya7Vt2orh3_0sy0kZ_300x300.jpg',
138
+ 'https://images.craigslist.org/00101_5QHY4S2Z5sA_0CI0t2_300x300.jpg',
139
+ 'https://images.craigslist.org/01515_ffmvYbqaDE5z_0db0il_300x300.jpg',
140
+ 'https://images.craigslist.org/00Y0Y_k4BLtlmy4G3_0t20CI_300x300.jpg',
141
+ 'https://images.craigslist.org/00f0f_8UqaoVSYmF3_0t20CI_300x300.jpg',
142
+ 'https://images.craigslist.org/00S0S_gzUw88HCvAJ_0t20CI_300x300.jpg',
143
+ 'https://images.craigslist.org/00y0y_33hz0Z55b4q_0t20CI_300x300.jpg',
144
+ 'https://images.craigslist.org/00303_1C1jCIIZv0j_0vC0sU_300x300.jpg',
145
+ 'https://images.craigslist.org/00e0e_8CkDtXcKJT8_0t20CI_300x300.jpg',
146
+ 'https://images.craigslist.org/00y0y_51A8H2vN373_0lM0CI_300x300.jpg',
147
+ 'https://images.craigslist.org/00L0L_dRk0jnEpyOt_0ak07K_300x300.jpg',
148
+ 'https://images.craigslist.org/00y0y_4k0av28SZ2D_0t20CI_300x300.jpg',
149
+ 'https://images.craigslist.org/00q0q_bl8M6uDFhu6_0lN0CI_300x300.jpg',
150
+ 'https://images.craigslist.org/00s0s_gWI3X0WADJl_0t20CI_300x300.jpg',
151
+ 'https://images.craigslist.org/00a0a_acXah02uvOWz_0iP0CI_300x300.jpg',
152
+ 'https://images.craigslist.org/00J0J_8ic6GHco0hWz_0iP0CI_300x300.jpg',
153
+ 'https://images.craigslist.org/00909_kX0yxtyNj3Kz_0CI0iP_300x300.jpg',
154
+ 'https://images.craigslist.org/00r0r_aQuKshg2RWz_0CI0m5_300x300.jpg',
155
+ 'https://images.craigslist.org/00D0D_EXbdo4OwAIz_0CI0iP_300x300.jpg',
156
+ 'https://images.craigslist.org/00c0c_7XCCCRjC45Xz_0qw0r6_300x300.jpg',
157
+ 'https://images.craigslist.org/00909_3pVbsQjmG3fz_0iF0t2_300x300.jpg',
158
+ 'https://images.craigslist.org/00x0x_fDO78qt9EhBz_0kZ0t2_300x300.jpg',
159
+ 'https://images.craigslist.org/00y0y_zub3q9oOAoz_0gH0t2_300x300.jpg',
160
+ 'https://images.craigslist.org/00L0L_kEafUzBefJVz_0kn0t2_300x300.jpg',
161
+ 'https://images.craigslist.org/01515_9YtDTZJoRdN_0sv0t2_300x300.jpg',
162
+ 'https://images.craigslist.org/00l0l_hxUFSVGPN90_0bC0fu_300x300.jpg',
163
+ 'https://images.craigslist.org/00000_9Xu5oAHrbD2z_0bC0fu_300x300.jpg',
164
+ 'https://images.craigslist.org/00606_c9HQzKcHUI5_0CI0t2_300x300.jpg',
165
+ 'https://images.craigslist.org/00R0R_f11XTZaLsnr_0CI0t2_300x300.jpg',
166
+ 'https://images.craigslist.org/00l0l_hAeQ6VO5Yqx_0CI0t2_300x300.jpg',
167
+ 'https://images.craigslist.org/00y0y_kERv1dOnpIW_0CI0t2_300x300.jpg',
168
+ 'https://images.craigslist.org/00n0n_dE2JSzTa8RV_0t20CI_300x300.jpg',
169
+ 'https://images.craigslist.org/00606_g7nMdIjUPlJ_0CI0t2_300x300.jpg',
170
+ 'https://images.craigslist.org/00d0d_aPBp3AfINh1_0CI0pO_300x300.jpg',
171
+ 'https://images.craigslist.org/00707_lVPnZIWolSD_0t20t2_300x300.jpg',
172
+ 'https://images.craigslist.org/00L0L_joIASkfRRhf_0lM0t2_300x300.jpg',
173
+ 'https://images.craigslist.org/00U0U_cwXe5LmtUCd_0CI0lM_300x300.jpg',
174
+ 'https://images.craigslist.org/00b0b_biVTywYkm10z_0jm09p_300x300.jpg',
175
+ 'https://images.craigslist.org/00E0E_j8mZhHXmG8Z_0t20CI_300x300.jpg',
176
+ 'https://images.craigslist.org/01414_buxYPX1YJUj_0lM0t2_300x300.jpg',
177
+ 'https://images.craigslist.org/00Y0Y_5eD6SeQl6Tb_0fu0bC_300x300.jpg',
178
+ 'https://images.craigslist.org/00606_brXAhtRTyjH_0t20CI_300x300.jpg',
179
+ 'https://images.craigslist.org/00S0S_cn6Niv51N8L_0dq0t2_300x300.jpg',
180
+ 'https://images.craigslist.org/00Y0Y_5eD6SeQl6Tb_0fu0bC_300x300.jpg',
181
+ 'https://images.craigslist.org/00p0p_2zn1fqnv4URz_0sa0By_300x300.jpg',
182
+ 'https://images.craigslist.org/00o0o_bgRDCriNfxcz_0fu0kE_300x300.jpg',
183
+ 'https://images.craigslist.org/00w0w_cnV5ulfFsjKz_0oo0bR_300x300.jpg',
184
+ 'https://images.craigslist.org/01717_FvloHH4Qzx_0CI0iP_300x300.jpg',
185
+ 'https://images.craigslist.org/01717_caGn7zohVK9z_0ww0fO_300x300.jpg',
186
+ 'https://images.craigslist.org/00e0e_lvI5xKTS3wxz_0i40ww_300x300.jpg',
187
+ 'https://images.craigslist.org/00r0r_cABhiHxo8YSz_0fK0ww_300x300.jpg',
188
+ 'https://images.craigslist.org/00R0R_gEELQEQo5x4z_0ww0fO_300x300.jpg',
189
+ 'https://images.craigslist.org/01717_lSJKVNpvnviz_0ww0fO_300x300.jpg',
190
+ 'https://images.craigslist.org/00606_iwznQHvGoJm_0CI0t2_300x300.jpg',
191
+ 'https://images.craigslist.org/00G0G_4pUkZMsT3rZz_0ww0fO_300x300.jpg',
192
+ 'https://images.craigslist.org/00d0d_5WJueKWKEfKz_0ww0fO_300x300.jpg',
193
+ 'https://images.craigslist.org/00W0W_dcJchrznGvj_0CI0t2_300x300.jpg',
194
+ 'https://images.craigslist.org/00101_5XUSciY7rmrz_0i40ww_300x300.jpg',
195
+ 'https://images.craigslist.org/01616_evTksoWGYg_0Cz0t2_300x300.jpg',
196
+ 'https://images.craigslist.org/00U0U_1fFrJg6sPDZ_0Cz0t2_300x300.jpg',
197
+ 'https://images.craigslist.org/01616_5xJlvbt7a9b_0hq09O_300x300.jpg',
198
+ 'https://images.craigslist.org/00d0d_lMWBVtjMnHY_03205a_300x300.jpg',
199
+ 'https://images.craigslist.org/00404_cC5xefqPNIv_0hq09O_300x300.jpg',
200
+ 'https://images.craigslist.org/00y0y_7CxaxHsZ3Z1_0lM0t2_300x300.jpg',
201
+ 'https://images.craigslist.org/00O0O_1s0gzObVAGz_0CI0t2_300x300.jpg',
202
+ 'https://images.craigslist.org/00Z0Z_lHdcJV1BLSMz_0CI0t2_300x300.jpg',
203
+ 'https://images.craigslist.org/00p0p_cdJGQJTda6hz_0CI0t2_300x300.jpg',
204
+ 'https://images.craigslist.org/00M0M_eXf4KqmgYXWz_0CI0t2_300x300.jpg',
205
+ 'https://images.craigslist.org/00G0G_4WKmfvyXLk7z_0i40ww_300x300.jpg',
206
+ 'https://images.craigslist.org/00C0C_3QnxkcOlnvnz_0jL0ob_300x300.jpg',
207
+ 'https://images.craigslist.org/00F0F_7EmU5PvBKx7_0CI0oc_300x300.jpg',
208
+ 'https://images.craigslist.org/00U0U_huBmSyQdZk2_0CI0it_300x300.jpg',
209
+ 'https://images.craigslist.org/00g0g_7gkDQ2IQDrH_0CI0vp_300x300.jpg',
210
+ 'https://images.craigslist.org/00y0y_20B1d7AKI7f_0CI0t2_300x300.jpg',
211
+ 'https://images.craigslist.org/00707_27Lc3wFqGYh_0t20CI_300x300.jpg',
212
+ 'https://images.craigslist.org/00y0y_20B1d7AKI7f_0CI0t2_300x300.jpg',
213
+ 'https://images.craigslist.org/00p0p_i9BsLDhipKS_0CI0t2_300x300.jpg',
214
+ 'https://images.craigslist.org/00808_83OfVZISXam_0C30t2_300x300.jpg',
215
+ 'https://images.craigslist.org/00p0p_i9BsLDhipKS_0CI0t2_300x300.jpg',
216
+ 'https://images.craigslist.org/01313_hUr5sxkEZuj_0t20CI_300x300.jpg',
217
+ 'https://images.craigslist.org/00k0k_fV6KDePgio6z_0t20CI_300x300.jpg',
218
+ 'https://images.craigslist.org/00j0j_do8Cs7sGsRGz_0t20CI_300x300.jpg',
219
+ 'https://images.craigslist.org/00F0F_4b4TiyN1PgL_0t20CI_300x300.jpg',
220
+ 'https://images.craigslist.org/00t0t_69fXsouHG1v_0t20CI_300x300.jpg',
221
+ 'https://images.craigslist.org/00606_1fJBCuOgT9C_0t20CI_300x300.jpg',
222
+ 'https://images.craigslist.org/00T0T_fy3UCafvBwX_0jm0pO_300x300.jpg',
223
+ 'https://images.craigslist.org/00606_1fJBCuOgT9C_0t20CI_300x300.jpg',
224
+ 'https://images.craigslist.org/00d0d_5WJueKWKEfKz_0ww0fO_300x300.jpg',
225
+ 'https://images.craigslist.org/00T0T_2UaFGLoJ0f8_0CI0og_300x300.jpg',
226
+ 'https://images.craigslist.org/00d0d_87kvRy9Q8X8_0CI0t2_300x300.jpg',
227
+ 'https://images.craigslist.org/00000_ixg1Jdb1FlV_0CI0nH_300x300.jpg',
228
+ 'https://images.craigslist.org/00a0a_jqLQr5pstgq_0oA0fN_300x300.jpg',
229
+ 'https://images.craigslist.org/00x0x_31bOHY9TQsh_0t20CI_300x300.jpg',
230
+ 'https://images.craigslist.org/00A0A_681SYGdOqhn_0hq0CI_300x300.jpg',
231
+ 'https://images.craigslist.org/00Z0Z_ajif0DJAxP1_0g80g8_300x300.jpg',
232
+ 'https://images.craigslist.org/00K0K_dzHgAqMrGLGz_04Q03V_300x300.jpg'
233
+ ]
234
+
235
+ # https://corvallis.craigslist.org/search/sss?hasPic=1
236
+ # Oregon Craigslist photos:
237
+ amateur_photos_oregon = [
238
+ 'https://images.craigslist.org/00p0p_fVxdWVxjJVb_0jm0aT_300x300.jpg',
239
+ 'https://images.craigslist.org/00t0t_3uGqyoVGbmW_0lM0t2_300x300.jpg',
240
+ 'https://images.craigslist.org/00b0b_elegFK6kgIm_0tR0CI_300x300.jpg',
241
+ 'https://images.craigslist.org/00a0a_iE7xwWgIgIQ_0t20CI_300x300.jpg',
242
+ 'https://images.craigslist.org/00r0r_1y6ijBHvDTH_0t20CI_300x300.jpg',
243
+ 'https://images.craigslist.org/00B0B_8AoXANOxiFR_0sB0t2_300x300.jpg',
244
+ 'https://images.craigslist.org/01414_46u2lZcGKFp_07e05K_300x300.jpg',
245
+ 'https://images.craigslist.org/01717_jUPn0bjRssX_0CI0pE_300x300.jpg',
246
+ 'https://images.craigslist.org/00000_bYxMxn4YnWK_0Ai0t2_300x300.jpg',
247
+ 'https://images.craigslist.org/01313_2L7BixrXlcf_0il0CI_300x300.jpg',
248
+ 'https://images.craigslist.org/00i0i_i0Riye8qDij_0CI0t2_300x300.jpg',
249
+ 'https://images.craigslist.org/00Z0Z_3kLVZ8Chlhh_0t20CI_300x300.jpg',
250
+ 'https://images.craigslist.org/00R0R_7G6aBbKn2O2_0t20CI_300x300.jpg',
251
+ 'https://images.craigslist.org/01313_2L7BixrXlcf_0il0CI_300x300.jpg',
252
+ 'https://images.craigslist.org/00B0B_lTvkrFUTUWbz_0CI0bW_300x300.jpg',
253
+ 'https://images.craigslist.org/00606_doUiFlSfqmHz_0x20oM_300x300.jpg',
254
+ 'https://images.craigslist.org/00b0b_afARmDcC0PU_0t20CI_300x300.jpg',
255
+ 'https://images.craigslist.org/00J0J_lnVMGiHhSdw_0CI0t2_300x300.jpg',
256
+ 'https://images.craigslist.org/00L0L_hp6YY3VDzMqz_0CI0t2_300x300.jpg',
257
+ 'https://images.craigslist.org/00E0E_gTg80g0iWDjz_0CI0t2_300x300.jpg',
258
+ 'https://images.craigslist.org/00V0V_3kvwYpV48lW_0CI0t2_300x300.jpg',
259
+ 'https://images.craigslist.org/01414_8Hai7RT1DJmz_0t20CI_300x300.jpg',
260
+ 'https://images.craigslist.org/00n0n_2b0oyVitXEGz_0CI0t2_300x300.jpg',
261
+ 'https://images.craigslist.org/00n0n_5Lx9gU6QUSiz_0lM0t2_300x300.jpg',
262
+ 'https://images.craigslist.org/00K0K_2IuSY6CyMN7z_0lM0t2_300x300.jpg',
263
+ 'https://images.craigslist.org/00808_hAmF0SA84D7z_0CI0t2_300x300.jpg',
264
+ 'https://images.craigslist.org/00L0L_1wgAGViZMmV_0CI0t2_300x300.jpg',
265
+ 'https://images.craigslist.org/00000_eOXpZyWj7Hnz_0CI0t2_300x300.jpg',
266
+ 'https://images.craigslist.org/00q0q_3aojkmvdWtWz_0CI0t2_300x300.jpg',
267
+ 'https://images.craigslist.org/00n0n_7uvxXBv83q6z_0CI0t2_300x300.jpg',
268
+ 'https://images.craigslist.org/00o0o_f27C1vADBxNz_0CI0t2_300x300.jpg',
269
+ 'https://images.craigslist.org/00O0O_dypjbnyFuDcz_0t20CI_300x300.jpg',
270
+ 'https://images.craigslist.org/00Z0Z_84WFbPjbyhkz_0da09S_300x300.jpg',
271
+ 'https://images.craigslist.org/00c0c_hssP62JAqJ1z_0lM0t2_300x300.jpg',
272
+ 'https://images.craigslist.org/00Y0Y_cYTH4ImUarSz_0fu0bC_300x300.jpg',
273
+ 'https://images.craigslist.org/00v0v_ftRAZKqf7QNz_0CI0t2_300x300.jpg',
274
+ 'https://images.craigslist.org/00C0C_9n5Qvx6YrS5z_0CI0t2_300x300.jpg',
275
+ 'https://images.craigslist.org/00a0a_kRcOFbjzcjwz_0hQ0CI_300x300.jpg',
276
+ 'https://images.craigslist.org/01414_hl2TnrQfbe4_0gG0t2_300x300.jpg',
277
+ 'https://images.craigslist.org/00Z0Z_2krTFwRtwPq_0lM0CI_300x300.jpg',
278
+ 'https://images.craigslist.org/00i0i_8h1tSh5am92_0t20CI_300x300.jpg',
279
+ 'https://images.craigslist.org/00Y0Y_X6IYDfBvwm_0lM0CI_300x300.jpg',
280
+ 'https://images.craigslist.org/00D0D_kbYUiEdLx2p_0CI0t2_300x300.jpg',
281
+ 'https://images.craigslist.org/00606_dUwX2xdWOY4_0t20CI_300x300.jpg',
282
+ 'https://images.craigslist.org/00C0C_jhCTCuwoL0yz_0CI0t2_300x300.jpg',
283
+ 'https://images.craigslist.org/00505_YLr5Wiru3S_0lM0CI_300x300.jpg',
284
+ 'https://images.craigslist.org/00606_kzeT6n1sNy4_0t20CI_300x300.jpg',
285
+ 'https://images.craigslist.org/01111_cnnSt51wyw1z_076076_300x300.jpg',
286
+ 'https://images.craigslist.org/00G0G_7gf5wDl26fXz_0t20CI_300x300.jpg',
287
+ 'https://images.craigslist.org/00k0k_9YGj74lPOGf_0lM0t2_300x300.jpg',
288
+ 'https://images.craigslist.org/00v0v_anU9V0rcxN1z_0gl0t2_300x300.jpg',
289
+ 'https://images.craigslist.org/00b0b_6rj1rxnmcP3_0lM0CI_300x300.jpg',
290
+ 'https://images.craigslist.org/00404_7l4xPkzv6ga_0lM0CI_300x300.jpg',
291
+ 'https://images.craigslist.org/00T0T_cV6C1NWVTt_0t20CI_300x300.jpg',
292
+ 'https://images.craigslist.org/00F0F_hgYKX0qwuQo_0lM0CI_300x300.jpg',
293
+ 'https://images.craigslist.org/00909_54WiNDsP4gR_0th0CI_300x300.jpg',
294
+ 'https://images.craigslist.org/00q0q_2OtYoEXCDLwz_09G06s_300x300.jpg',
295
+ 'https://images.craigslist.org/00A0A_aoTM3UmKdqS_1320MM_300x300.jpg',
296
+ 'https://images.craigslist.org/00L0L_g8scaYvXt3T_0t20CI_300x300.jpg',
297
+ 'https://images.craigslist.org/00l0l_7ImFuDhX661z_0mh0t2_300x300.jpg',
298
+ 'https://images.craigslist.org/00o0o_lMHeyeh8g2b_0jm0aT_300x300.jpg',
299
+ 'https://images.craigslist.org/00e0e_1P8UbJFuDxK_1320MM_300x300.jpg',
300
+ 'https://images.craigslist.org/01010_kcEPll19hhC_0CI0t2_300x300.jpg',
301
+ 'https://images.craigslist.org/00202_6ueAPFx6bk4z_0910ew_300x300.jpg',
302
+ 'https://images.craigslist.org/00N0N_fnaFlq5MxLt_0t20CI_300x300.jpg',
303
+ 'https://images.craigslist.org/00s0s_8fi1vod1tYwz_09G07g_300x300.jpg',
304
+ 'https://images.craigslist.org/00Y0Y_11DAxNoBLvF_0CI0t2_300x300.jpg',
305
+ 'https://images.craigslist.org/00W0W_kP02d2u4piD_0t20CI_300x300.jpg',
306
+ 'https://images.craigslist.org/00808_gH51sNf4lVJ_0CI0t2_300x300.jpg',
307
+ 'https://images.craigslist.org/00n0n_93rVz9sAcjg_0t20CI_300x300.jpg',
308
+ 'https://images.craigslist.org/00l0l_7bm41LQZizz_0t20CI_300x300.jpg',
309
+ 'https://images.craigslist.org/00R0R_4NMLXtLZIb9z_0t20CI_300x300.jpg',
310
+ 'https://images.craigslist.org/00R0R_4NMLXtLZIb9z_0t20CI_300x300.jpg',
311
+ 'https://images.craigslist.org/00L0L_fpeCvGTrxqU_0t20CI_300x300.jpg',
312
+ 'https://images.craigslist.org/00e0e_4OkfeN6lusm_0d40t2_300x300.jpg',
313
+ 'https://images.craigslist.org/00M0M_4KIMK2lxEnj_0t20CI_300x300.jpg',
314
+ 'https://images.craigslist.org/00j0j_iRlSOUzGewD_0hR0CI_300x300.jpg',
315
+ 'https://images.craigslist.org/00O0O_eql7f7FUIU6z_0pp0t2_300x300.jpg',
316
+ 'https://images.craigslist.org/00E0E_gQEksD31WIL_0lM0CI_300x300.jpg',
317
+ 'https://images.craigslist.org/00V0V_iBbhzvrWdYOz_0aT0ew_300x300.jpg',
318
+ 'https://images.craigslist.org/00707_1uuF37GVUiz_0t20CI_300x300.jpg',
319
+ 'https://images.craigslist.org/00o0o_clr0Db0AInJ_07v0a0_300x300.jpg',
320
+ 'https://images.craigslist.org/00D0D_7ovR9JRViVb_0t20CI_300x300.jpg',
321
+ 'https://images.craigslist.org/01010_b3mCUirtFBJ_0jm0jm_300x300.jpg',
322
+ 'https://images.craigslist.org/00t0t_6KZqrc5cqw0_0pO0jm_300x300.jpg',
323
+ 'https://images.craigslist.org/00U0U_gwsqwXwmDZr_0CI0iP_300x300.jpg',
324
+ 'https://images.craigslist.org/00X0X_hKWYLtk0CbC_0t20CI_300x300.jpg',
325
+ 'https://images.craigslist.org/00u0u_1SFApp7DEt2z_0aT0ew_300x300.jpg',
326
+ 'https://images.craigslist.org/00N0N_4xa8nbCcpd2_0CI0t2_300x300.jpg',
327
+ 'https://images.craigslist.org/01717_69MOM9JNwYvz_0t20CI_300x300.jpg',
328
+ 'https://images.craigslist.org/00505_gTa5PA0x3Enz_0t20CI_300x300.jpg',
329
+ 'https://images.craigslist.org/00g0g_9hBrdam6G67_0CI0t2_300x300.jpg',
330
+ 'https://images.craigslist.org/00B0B_8N4zrjHMWKc_0t20CI_300x300.jpg',
331
+ 'https://images.craigslist.org/00m0m_1SFApp7DEt2_0aT0ew_300x300.jpg',
332
+ 'https://images.craigslist.org/00v0v_3N1l7vfP9oX_0t20CI_300x300.jpg',
333
+ 'https://images.craigslist.org/00E0E_i7w9xzQ4DVnz_0Cr0t2_300x300.jpg',
334
+ 'https://images.craigslist.org/00C0C_9Pme5Q5Fab4z_0830cU_300x300.jpg',
335
+ 'https://images.craigslist.org/00C0C_9Pme5Q5Fab4z_0830cU_300x300.jpg',
336
+ 'https://images.craigslist.org/00U0U_2ImDoMOrJg1_0lM0t2_300x300.jpg',
337
+ 'https://images.craigslist.org/00S0S_kgHOeKxpbE0_0t20CI_300x300.jpg',
338
+ 'https://images.craigslist.org/00J0J_gcavERpafL5_0CI0t2_300x300.jpg',
339
+ 'https://images.craigslist.org/00Q0Q_fn6dOVjOrhq_05O07K_300x300.jpg',
340
+ 'https://images.craigslist.org/00h0h_gNXXK78iUzB_0k10t2_300x300.jpg',
341
+ 'https://images.craigslist.org/00b0b_4JxBUlc1eDT_07K0ak_300x300.jpg',
342
+ 'https://images.craigslist.org/00V0V_ks1vocYQacpz_0fu0bC_300x300.jpg',
343
+ 'https://images.craigslist.org/01010_fGeu0ggYIE1z_0fu0bC_300x300.jpg',
344
+ 'https://images.craigslist.org/00N0N_9Kv90TDMVQmz_0fu0bC_300x300.jpg',
345
+ 'https://images.craigslist.org/01616_6gtu5DweqMK_0t20CI_300x300.jpg',
346
+ 'https://images.craigslist.org/00t0t_jiuBppu6cah_0CI0t2_300x300.jpg',
347
+ 'https://images.craigslist.org/00D0D_awLxMdri04H_0gl0t2_300x300.jpg',
348
+ 'https://images.craigslist.org/00L0L_lMpIOyA7a5P_0CI0t2_300x300.jpg',
349
+ 'https://images.craigslist.org/00J0J_34dt5RdFZGL_0CI0t2_300x300.jpg',
350
+ 'https://images.craigslist.org/00w0w_3lBvw0Wz9ba_0t20CI_300x300.jpg',
351
+ 'https://images.craigslist.org/00u0u_75151uOteJ3_0t20CI_300x300.jpg',
352
+ 'https://images.craigslist.org/00X0X_kkfRyb2oCcc_0ak07K_300x300.jpg',
353
+ 'https://images.craigslist.org/01616_fiBrckaM2EF_0t20CI_300x300.jpg',
354
+ 'https://images.craigslist.org/00Z0Z_djGI9GIn02H_07K0ak_300x300.jpg',
355
+ 'https://images.craigslist.org/00808_4JusbeQ1pY3_0t20CI_300x300.jpg',
356
+ 'https://images.craigslist.org/00X0X_kkfRyb2oCcc_0ak07K_300x300.jpg',
357
+ 'https://images.craigslist.org/00H0H_joPQWU3gAR7_07K0ak_300x300.jpg'
358
+ ]
359
+
360
+ # Pennsylvania Craigslist photos:
361
+ amateur_photos_pennsylvania = [
362
+ 'https://images.craigslist.org/00Z0Z_HhMkxBontE_0g80g8_300x300.jpg',
363
+ 'https://images.craigslist.org/00202_l1Lb4mg6euW_0g40c8_300x300.jpg',
364
+ 'https://images.craigslist.org/00p0p_jZA5ydo5i64_0t20CI_300x300.jpg',
365
+ 'https://images.craigslist.org/00u0u_bDRM4NX3f93z_0hq0CI_300x300.jpg',
366
+ 'https://images.craigslist.org/00V0V_jF9bzJcO8N0_0ak07K_300x300.jpg',
367
+ 'https://images.craigslist.org/00d0d_94T9sVbEurTz_0lj0t2_300x300.jpg',
368
+ 'https://images.craigslist.org/00l0l_kmYH924pYno_0t20CI_300x300.jpg',
369
+ 'https://images.craigslist.org/00A0A_g9nZYWwCvuE_0CI0t2_300x300.jpg',
370
+ 'https://images.craigslist.org/00y0y_boXiLGz1BMV_0t20CI_300x300.jpg',
371
+ 'https://images.craigslist.org/00t0t_9Gd8CP1vVGO_0t20CI_300x300.jpg',
372
+ 'https://images.craigslist.org/00x0x_9Z9K1uIG6dK_0CI0t2_300x300.jpg',
373
+ 'https://images.craigslist.org/00000_2EOVFflaR5G_0CI0t2_300x300.jpg',
374
+ 'https://images.craigslist.org/00b0b_1tlTvrbvDSkz_04B04G_300x300.jpg',
375
+ 'https://images.craigslist.org/00v0v_7K66cOSxyBjz_0CI0n8_300x300.jpg',
376
+ 'https://images.craigslist.org/00b0b_1tlTvrbvDSkz_04B04G_300x300.jpg',
377
+ 'https://images.craigslist.org/00606_pDV8R3FgdU_0CI0t2_300x300.jpg',
378
+ 'https://images.craigslist.org/00707_hDjm5yQzMF5_0CI0t2_300x300.jpg',
379
+ 'https://images.craigslist.org/00707_kSIDH6ylX9Oz_0od0t2_300x300.jpg',
380
+ 'https://images.craigslist.org/01212_7R2lYNauwOKz_0cR0e9_300x300.jpg',
381
+ 'https://images.craigslist.org/00j0j_72x6knlmWkAz_0CI0t2_300x300.jpg',
382
+ 'https://images.craigslist.org/00U0U_9clNdBGuen5_0lR0t2_300x300.jpg',
383
+ 'https://images.craigslist.org/00F0F_8YYYY5qAine_0p60t2_300x300.jpg',
384
+ 'https://images.craigslist.org/00h0h_adhi4UI4eGa_0CI0t2_300x300.jpg',
385
+ 'https://images.craigslist.org/00N0N_7dzRvUSgGUVz_0CI0t2_300x300.jpg',
386
+ 'https://images.craigslist.org/00R0R_9nY8B7q0hCe_0t20CI_300x300.jpg',
387
+ 'https://images.craigslist.org/00J0J_3zf5o9j2YgH_0t20CI_300x300.jpg',
388
+ 'https://images.craigslist.org/00909_blZhXYfcMp4_0CI0t2_300x300.jpg',
389
+ 'https://images.craigslist.org/00303_ehYaQiDjpsU_0jm0pO_300x300.jpg',
390
+ 'https://images.craigslist.org/00D0D_56PcLACIWRSz_0rO0kR_300x300.jpg',
391
+ 'https://images.craigslist.org/00303_giy9IIEHMxt_0CI0t2_300x300.jpg',
392
+ 'https://images.craigslist.org/01515_7EahhRC6sHC_0dq0t2_300x300.jpg',
393
+ 'https://images.craigslist.org/00z0z_fSa1MjFqxpx_0aT0ew_300x300.jpg',
394
+ 'https://images.craigslist.org/00g0g_leO695exVJ1z_0ww0oo_300x300.jpg',
395
+ 'https://images.craigslist.org/01616_k4ERTKSbGmLz_0CI0t2_300x300.jpg',
396
+ 'https://images.craigslist.org/00q0q_ifXWR5u7MHCz_0CI0t2_300x300.jpg',
397
+ 'https://images.craigslist.org/00G0G_34P9QjDQRBCz_0CI0t2_300x300.jpg',
398
+ 'https://images.craigslist.org/00F0F_47gtkWdGjcxz_0CI0t2_300x300.jpg',
399
+ 'https://images.craigslist.org/01515_bZs0QMIMtCQz_0CI0t2_300x300.jpg',
400
+ 'https://images.craigslist.org/00K0K_3ivAKOqPSAt_0CI0t2_300x300.jpg',
401
+ 'https://images.craigslist.org/00B0B_iVCpbZGHEfZ_0CI0t2_300x300.jpg',
402
+ 'https://images.craigslist.org/00G0G_50owFT81UxK_0t20CI_300x300.jpg',
403
+ 'https://images.craigslist.org/00T0T_gYvcqGpdSSe_0lM0t2_300x300.jpg',
404
+ 'https://images.craigslist.org/00P0P_fbvYRoh3iuu_0ew0t2_300x300.jpg',
405
+ 'https://images.craigslist.org/00H0H_i7LBBZdFFQU_0hq0d4_300x300.jpg',
406
+ 'https://images.craigslist.org/00n0n_lQ2zqFWGlLC_0hq0ne_300x300.jpg',
407
+ 'https://images.craigslist.org/00x0x_jiybf4mjPeS_0d40hq_300x300.jpg',
408
+ 'https://images.craigslist.org/00J0J_8L4EMo9YT30_0hq0d4_300x300.jpg',
409
+ 'https://images.craigslist.org/00t0t_Kfv5R7pTx1_0jI0eM_300x300.jpg',
410
+ 'https://images.craigslist.org/00N0N_3l6iblTQGLh_0hq0d4_300x300.jpg',
411
+ 'https://images.craigslist.org/00202_ksD3EAsCdE6_0d40hq_300x300.jpg',
412
+ 'https://images.craigslist.org/01515_2Zp0ivI6yOa_0hq0d4_300x300.jpg',
413
+ 'https://images.craigslist.org/00l0l_lvrkqQn7Zhh_0hq0d4_300x300.jpg',
414
+ 'https://images.craigslist.org/00H0H_6wNjQUW6DVk_0iE0dZ_300x300.jpg',
415
+ 'https://images.craigslist.org/00I0I_2w0Agximwsj_0CI0t2_300x300.jpg',
416
+ 'https://images.craigslist.org/01010_8YSvcBSIVIy_0CI0t2_300x300.jpg',
417
+ 'https://images.craigslist.org/00k0k_UhFc0dfudG_0hT0CI_300x300.jpg',
418
+ 'https://images.craigslist.org/00k0k_UhFc0dfudG_0hT0CI_300x300.jpg',
419
+ 'https://images.craigslist.org/01717_cCTRrv9CctG_0t20CI_300x300.jpg',
420
+ 'https://images.craigslist.org/01717_hsjgWvdvfsr_0aT0ew_300x300.jpg',
421
+ 'https://images.craigslist.org/00b0b_bUwP2qykNUOz_0dW0iA_300x300.jpg',
422
+ 'https://images.craigslist.org/00f0f_iaHXdSLZOWvz_06s04w_300x300.jpg',
423
+ 'https://images.craigslist.org/00x0x_boaXrVxrUS2_0lM0CI_300x300.jpg',
424
+ 'https://images.craigslist.org/00s0s_1HhF7CfZB6o_0t20CI_300x300.jpg',
425
+ 'https://images.craigslist.org/00P0P_bG9V3TBID6yz_0t20CI_300x300.jpg',
426
+ 'https://images.craigslist.org/00B0B_8wYNrAhHpen_0yp0t2_300x300.jpg',
427
+ 'https://images.craigslist.org/00K0K_b8YnhjBGzAuz_0CI0t2_300x300.jpg',
428
+ 'https://images.craigslist.org/00l0l_3GCt6eXzWa6_0t20CI_300x300.jpg',
429
+ 'https://images.craigslist.org/00l0l_gZm6O1lRmCm_0pO0jm_300x300.jpg',
430
+ 'https://images.craigslist.org/00g0g_fpZ8TyOr66F_1320MM_300x300.jpg',
431
+ 'https://images.craigslist.org/00P0P_ePZxFtw3h19_0CI0t2_300x300.jpg',
432
+ 'https://images.craigslist.org/00r0r_6dzEtWC3EIR_0t20CI_300x300.jpg',
433
+ 'https://images.craigslist.org/00Z0Z_8lyB0GTGN5R_0t20CI_300x300.jpg',
434
+ 'https://images.craigslist.org/00909_lsVk82VfTFm_08B06s_300x300.jpg',
435
+ 'https://images.craigslist.org/00f0f_hkAJ16hkJDiz_06s08B_300x300.jpg',
436
+ 'https://images.craigslist.org/00n0n_d7AMxacdeahz_06s08B_300x300.jpg',
437
+ 'https://images.craigslist.org/01212_gI46z4XvrJkz_06s04Q_300x300.jpg',
438
+ 'https://images.craigslist.org/00f0f_975Q7TCenNgz_06s04Q_300x300.jpg',
439
+ 'https://images.craigslist.org/00d0d_bCIZ45yD5g7z_06s08B_300x300.jpg',
440
+ 'https://images.craigslist.org/01313_5Mi0b4EJ8tQz_06s08B_300x300.jpg',
441
+ 'https://images.craigslist.org/00c0c_alBwUQaEzogz_06s08B_300x300.jpg',
442
+ 'https://images.craigslist.org/00m0m_76TYVr0Rt91z_06s04Q_300x300.jpg',
443
+ 'https://images.craigslist.org/00w0w_51QPag7mf90_06s08B_300x300.jpg',
444
+ 'https://images.craigslist.org/00N0N_7Pc3864Rtsz_06s08B_300x300.jpg',
445
+ 'https://images.craigslist.org/00s0s_ecMJA0RLJb1z_06s08B_300x300.jpg',
446
+ 'https://images.craigslist.org/00r0r_cHFSy1cdeft_0CI0t2_300x300.jpg',
447
+ 'https://images.craigslist.org/00d0d_98EaTfXbyzk_0t20CI_300x300.jpg',
448
+ 'https://images.craigslist.org/01616_8WGZwoPtjUZz_0CI0t2_300x300.jpg',
449
+ 'https://images.craigslist.org/00A0A_b7IYLjReeye_01W02A_300x300.jpg',
450
+ 'https://images.craigslist.org/00202_l1V63yiL19n_0CI0t2_300x300.jpg',
451
+ 'https://images.craigslist.org/00S0S_989GUflKxKa_0t20CI_300x300.jpg',
452
+ 'https://images.craigslist.org/01616_ecGN1eTeDtoz_09G07g_300x300.jpg',
453
+ 'https://images.craigslist.org/00303_gjDMFV8M2Wb_04Q04M_300x300.jpg',
454
+ 'https://images.craigslist.org/00Y0Y_7lLGrscreyF_0CI0t2_300x300.jpg',
455
+ 'https://images.craigslist.org/00909_6M5rycwCdGO_0t20CI_300x300.jpg',
456
+ 'https://images.craigslist.org/01212_hmnm5PwL0ei_04a0aP_300x300.jpg',
457
+ 'https://images.craigslist.org/00G0G_czrGkcpC4Fo_0jm0pO_300x300.jpg',
458
+ 'https://images.craigslist.org/01313_cr2pTOd7tLn_1320MM_300x300.jpg',
459
+ 'https://images.craigslist.org/00a0a_kneu5TDsG6V_0CI0t2_300x300.jpg',
460
+ 'https://images.craigslist.org/00O0O_d3TQgeGCHtF_0MM132_300x300.jpg',
461
+ 'https://images.craigslist.org/00w0w_2GyL7yoL9yc_1320MM_300x300.jpg',
462
+ 'https://images.craigslist.org/00x0x_iCC7Xmz8DHo_0CI0t2_300x300.jpg',
463
+ 'https://images.craigslist.org/00n0n_3W9aI6DwSOg_0CI0t2_300x300.jpg',
464
+ 'https://images.craigslist.org/00O0O_kOvC4I7bWNB_0t20CI_300x300.jpg',
465
+ 'https://images.craigslist.org/01111_btuFx0k1J9Y_0ak0ak_300x300.jpg',
466
+ 'https://images.craigslist.org/00L0L_dOl4pJEglD8_0CI0t2_300x300.jpg',
467
+ 'https://images.craigslist.org/00q0q_c2RjsXmfi2z_1320MM_300x300.jpg',
468
+ 'https://images.craigslist.org/00y0y_ga2xbqY0joSz_0CI0t2_300x300.jpg',
469
+ 'https://images.craigslist.org/01616_5N3wXM776vMz_0t20CI_300x300.jpg',
470
+ 'https://images.craigslist.org/00J0J_ivHjq6GI5Ud_0gw0co_300x300.jpg',
471
+ 'https://images.craigslist.org/00w0w_6MwyZY6JQzf_0t20CI_300x300.jpg',
472
+ 'https://images.craigslist.org/00n0n_stuPEoMp33z_0CI0t2_300x300.jpg',
473
+ 'https://images.craigslist.org/00Q0Q_bd7L7YSJwaGz_0CI0t2_300x300.jpg',
474
+ 'https://images.craigslist.org/00C0C_erzPThEJyaJz_0lM0t2_300x300.jpg',
475
+ 'https://images.craigslist.org/00303_8itPxqhI469z_0CI0t2_300x300.jpg',
476
+ 'https://images.craigslist.org/00202_bD6QXeYiIHLz_0jm0pO_300x300.jpg',
477
+ 'https://images.craigslist.org/00m0m_erTjg7WLro5z_09G06X_300x300.jpg',
478
+ 'https://images.craigslist.org/00c0c_aa0d1u0gZaMz_0CI0t2_300x300.jpg',
479
+ 'https://images.craigslist.org/00909_3w51bweIwWxz_0CI0t2_300x300.jpg',
480
+ 'https://images.craigslist.org/00X0X_br0eRSjKoAEz_0CI0t2_300x300.jpg',
481
+ 'https://images.craigslist.org/00p0p_9RL0I7Xgdbaz_0CI0t2_300x300.jpg'
482
+ ]
483
+
484
+ The rest of this notebook is taken mostly verbatim from the first exercise from fast.ai, found here:
485
+
486
+ https://www.kaggle.com/code/jhoward/is-it-a-bird-creating-a-model-from-your-own-data
487
+
488
+ These steps would be run online to take advantage of server resources, and not needing to download and setup the sizeable fast.ai packages.
489
+
490
+ #NB: Kaggle requires phone verification to use the internet or a GPU. If you haven't done that yet, the cell below will fail
491
+ # This code is only here to check that your internet is enabled. It doesn't do anything else.
492
+ # Here's a help thread on getting your phone number verified: https://www.kaggle.com/product-feedback/135367
493
+
494
+ import socket,warnings
495
+ try:
496
+ socket.setdefaulttimeout(1)
497
+ socket.socket(socket.AF_INET, socket.SOCK_STREAM).connect(('1.1.1.1', 53))
498
+ except socket.error as ex: raise Exception("STOP: No internet. Click '>|' in top right and set 'Internet' switch to on")
499
+
500
+ # It's a good idea to ensure you're running the latest version of any libraries you need.
501
+ # `!pip install -Uqq <libraries>` upgrades to the latest version of <libraries>
502
+ # NB: You can safely ignore any warnings or errors pip spits out about running as root or incompatibilities
503
+ import os
504
+ iskaggle = os.environ.get('KAGGLE_KERNEL_RUN_TYPE', '')
505
+
506
+ if iskaggle:
507
+ !pip install -Uqq fastai duckduckgo_search
508
+
509
+ ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.
510
+ tensorflow-io 0.21.0 requires tensorflow-io-gcs-filesystem==0.21.0, which is not installed.
511
+ explainable-ai-sdk 1.3.2 requires xai-image-widget, which is not installed.
512
+ dask-cudf 21.10.1 requires cupy-cuda114, which is not installed.
513
+ beatrix-jupyterlab 3.1.6 requires google-cloud-bigquery-storage, which is not installed.
514
+ tensorflow 2.6.2 requires numpy~=1.19.2, but you have numpy 1.20.3 which is incompatible.
515
+ tensorflow 2.6.2 requires six~=1.15.0, but you have six 1.16.0 which is incompatible.
516
+ tensorflow 2.6.2 requires typing-extensions~=3.7.4, but you have typing-extensions 3.10.0.2 which is incompatible.
517
+ tensorflow 2.6.2 requires wrapt~=1.12.1, but you have wrapt 1.13.3 which is incompatible.
518
+ tensorflow-transform 1.5.0 requires absl-py<0.13,>=0.9, but you have absl-py 0.15.0 which is incompatible.
519
+ tensorflow-transform 1.5.0 requires numpy<1.20,>=1.16, but you have numpy 1.20.3 which is incompatible.
520
+ tensorflow-transform 1.5.0 requires pyarrow<6,>=1, but you have pyarrow 6.0.1 which is incompatible.
521
+ tensorflow-transform 1.5.0 requires tensorflow!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,<2.8,>=1.15.2, but you have tensorflow 2.6.2 which is incompatible.
522
+ tensorflow-serving-api 2.7.0 requires tensorflow<3,>=2.7.0, but you have tensorflow 2.6.2 which is incompatible.
523
+ gcsfs 2021.11.1 requires fsspec==2021.11.1, but you have fsspec 2022.2.0 which is incompatible.
524
+ flake8 4.0.1 requires importlib-metadata<4.3; python_version < "3.8", but you have importlib-metadata 4.11.3 which is incompatible.
525
+ featuretools 1.6.0 requires numpy>=1.21.0, but you have numpy 1.20.3 which is incompatible.
526
+ dask-cudf 21.10.1 requires dask==2021.09.1, but you have dask 2022.2.0 which is incompatible.
527
+ dask-cudf 21.10.1 requires distributed==2021.09.1, but you have distributed 2022.2.0 which is incompatible.
528
+ apache-beam 2.34.0 requires dill<0.3.2,>=0.3.1.1, but you have dill 0.3.4 which is incompatible.
529
+ apache-beam 2.34.0 requires httplib2<0.20.0,>=0.8, but you have httplib2 0.20.2 which is incompatible.
530
+ apache-beam 2.34.0 requires pyarrow<6.0.0,>=0.15.1, but you have pyarrow 6.0.1 which is incompatible.
531
+ aioitertools 0.10.0 requires typing_extensions>=4.0; python_version < "3.10", but you have typing-extensions 3.10.0.2 which is incompatible.
532
+ aiobotocore 2.1.2 requires botocore<1.23.25,>=1.23.24, but you have botocore 1.24.20 which is incompatible.
533
+
534
+ Step 1: Download images of stock photography
535
+
536
+ from duckduckgo_search import ddg_images
537
+ from fastcore.all import *
538
+
539
+ def search_images(term, max_images):
540
+ print(f"Searching for '{term}'")
541
+ return L(ddg_images(term, max_results=max_images)).itemgot('image')
542
+
543
+ #NB: `search_images` depends on duckduckgo.com, which doesn't always return correct responses.
544
+ # If you get a JSON error, just try running it again (it may take a couple of tries).
545
+ urls = search_images('pixabay product', max_images=10)
546
+ #urls = search_images('bird photos', max_images=1)
547
+ #urls = search_images('stock photos product', max_images=1)
548
+ #urls = search_images('shutterstock product', max_images=1)
549
+ urls[5]
550
+
551
+ Searching for 'pixabay product'
552
+
553
+ 'https://cdn.pixabay.com/photo/2018/08/16/11/14/product-3610174_1280.jpg'
554
+
555
+ from fastdownload import download_url
556
+ dest = 'stock_product_photo.jpg'
557
+ download_url(urls[0], dest, show_progress=False)
558
+
559
+ from fastai.vision.all import *
560
+ im = Image.open(dest)
561
+ im.to_thumb(256,256)
562
+
563
+ download_url(amateur_photos_virginia[0], 'amateur_product_photo.jpg', show_progress=False)
564
+ Image.open('amateur_product_photo.jpg').to_thumb(256,256)
565
+
566
+ categories = 'stock','amateur'
567
+ path = Path('stock_or_amateur')
568
+
569
+ from time import sleep
570
+
571
+ s = 'stock'
572
+ dest_s = (path/s)
573
+ # Clean up from prior run if needed
574
+ if os.path.isdir(dest_s):
575
+ shutil.rmtree(dest_s)
576
+ dest_s.mkdir(exist_ok=True, parents=True)
577
+
578
+ stock_image_urls_product=search_images('pixabay product', 120)
579
+ download_images(dest_s, urls=stock_image_urls_product)
580
+ print(f"Number of stock product image URLs: {len(stock_image_urls_product)}")
581
+ sleep(8) # Pause between searches to avoid over-loading server
582
+ stock_image_urls_business=search_images('pixabay business', 120)
583
+ download_images(dest_s, urls=stock_image_urls_business)
584
+ print(f"Number of stock business image URLs: {len(stock_image_urls_business)}")
585
+ sleep(8)
586
+ stock_image_urls_industrial=search_images('pixabay industrial', 120)
587
+ download_images(dest_s, urls=stock_image_urls_industrial)
588
+ print(f"Number of stock industrial image URLs: {len(stock_image_urls_industrial)}")
589
+
590
+ resize_images(dest_s, max_size=400, dest=dest_s)
591
+ print(f"Total stock images downloaded: {len(get_image_files(dest_s))}")
592
+
593
+ Searching for 'pixabay product'
594
+ Number of stock product image URLs: 120
595
+ Searching for 'pixabay business'
596
+ Number of stock business image URLs: 120
597
+ Searching for 'pixabay industrial'
598
+ Number of stock industrial image URLs: 120
599
+
600
+ /opt/conda/lib/python3.7/site-packages/PIL/Image.py:963: UserWarning: Palette images with Transparency expressed in bytes should be converted to RGBA images
601
+ "Palette images with Transparency expressed in bytes should be "
602
+
603
+ Total stock images downloaded: 354
604
+
605
+ a = 'amateur'
606
+ dest_a = (path/a)
607
+ # Clean up from prior run if needed
608
+ if os.path.isdir(dest_a):
609
+ shutil.rmtree(dest_a)
610
+
611
+ dest_a.mkdir(exist_ok=True, parents=True)
612
+ download_images(dest_a, urls=amateur_photos_virginia) # hard coded above, may need to refresh
613
+ print(f"Number of amateur Virginia image URLs: {len(amateur_photos_virginia)}")
614
+ sleep(8)
615
+ download_images(dest_a, urls=amateur_photos_oregon) # hard coded above, may need to refresh
616
+ print(f"Number of amateur Oregon image URLs: {len(amateur_photos_oregon)}")
617
+ sleep(8)
618
+ download_images(dest_a, urls=amateur_photos_pennsylvania) # hard coded above, may need to refresh
619
+ print(f"Number of amateur Pennsylvania image URLs: {len(amateur_photos_pennsylvania)}")
620
+ resize_images(dest_a, max_size=400, dest=dest_a)
621
+
622
+ print(f"Total amateur images downloaded: {len(get_image_files(dest_a))}")
623
+
624
+ Number of amateur Virginia image URLs: 120
625
+ Number of amateur Oregon image URLs: 120
626
+ Number of amateur Pennsylvania image URLs: 120
627
+ Total amateur images downloaded: 360
628
+
629
+ Step 2: Train our model
630
+
631
+ Some photos might not download correctly which could cause our model training to fail, so we'll remove them:
632
+
633
+ failed = verify_images(get_image_files(path))
634
+ failed.map(Path.unlink)
635
+ print(f"Failed images removed: {len(failed)}")
636
+ total_num_images = len(get_image_files(path))
637
+ print(f"Total images after removal: {total_num_images}")
638
+
639
+ Failed images removed: 0
640
+ Total images after removal: 714
641
+
642
+ To train a model, we'll need DataLoaders, which is an object that contains a training set (the images used to create a model) and a validation set (the images used to check the accuracy of a model -- not used during training). In fastai we can create that easily using a DataBlock, and view sample images from it:
643
+
644
+ dls = DataBlock(
645
+ blocks=(ImageBlock, CategoryBlock),
646
+ get_items=get_image_files,
647
+ splitter=RandomSplitter(valid_pct=0.2, seed=42),
648
+ get_y=parent_label,
649
+ item_tfms=[Resize(192, method='squish')]
650
+ ).dataloaders(path, bs=32)
651
+
652
+ dls.show_batch(max_n=6)
653
+
654
+ Here what each of the DataBlock parameters means:
655
+
656
+ blocks=(ImageBlock, CategoryBlock),
657
+
658
+ The inputs to our model are images, and the outputs are categories (in this case, "bird" or "forest").
659
+
660
+ get_items=get_image_files,
661
+
662
+ To find all the inputs to our model, run the get_image_files function (which returns a list of all image files in a path).
663
+
664
+ splitter=RandomSplitter(valid_pct=0.2, seed=42),
665
+
666
+ Split the data into training and validation sets randomly, using 20% of the data for the validation set.
667
+
668
+ get_y=parent_label,
669
+
670
+ The labels (y values) is the name of the parent of each file (i.e. the name of the folder they're in, which will be bird or forest).
671
+
672
+ item_tfms=[Resize(192, method='squish')]
673
+
674
+ Before training, resize each image to 192x192 pixels by "squishing" it (as opposed to cropping it).
675
+
676
+ Now we're ready to train our model. The fastest widely used computer vision model is resnet18. You can train this in a few minutes, even on a CPU! (On a GPU, it generally takes under 10 seconds...)
677
+
678
+ fastai comes with a helpful fine_tune() method which automatically uses best practices for fine tuning a pre-trained model, so we'll use that.
679
+
680
+ learn = vision_learner(dls, resnet18, metrics=error_rate)
681
+ learn.fine_tune(3)
682
+
683
+ Downloading: "https://download.pytorch.org/models/resnet18-f37072fd.pth" to /root/.cache/torch/hub/checkpoints/resnet18-f37072fd.pth
684
+
685
+ 0%| | 0.00/44.7M [00:00<?, ?B/s]
686
+
687
+ epoch train_loss valid_loss error_rate time
688
+ 0 0.918096 0.318988 0.126761 00:09
689
+ epoch train_loss valid_loss error_rate time
690
+ 0 0.355654 0.180829 0.077465 00:04
691
+ 1 0.236539 0.240909 0.077465 00:03
692
+ 2 0.159012 0.190749 0.063380 00:03
693
+
694
+ Generally when I run this I see 100% accuracy on the validation set (although it might vary a bit from run to run).
695
+
696
+ "Fine-tuning" a model means that we're starting with a model someone else has trained using some other dataset (called the pretrained model), and adjusting the weights a little bit so that the model learns to recognise your particular dataset. In this case, the pretrained model was trained to recognise photos in imagenet, and widely-used computer vision dataset with images covering 1000 categories) For details on fine-tuning and why it's important, check out the free fast.ai course.
697
+ Step 3: Use our model (and build your own!)
698
+
699
+ Let's see what our model thinks about that bird we downloaded at the start:
700
+
701
+ # original:
702
+ #is_amateur_photo,_,probs = learn.predict(PILImage.create('stock_product_photo.jpg'))
703
+ # it seems as of the Feb 14th 2023 release of fastai 2.7.11 this causes an "attribute read error", eventually found that wrapping in tensor() fixed it:
704
+ is_amateur_photo,_,probs = learn.predict(tensor(PILImage.create('stock_product_photo.jpg')))
705
+ print(f"This is a: {is_amateur_photo} photo.")
706
+ print(f"Probability it's an amateur photo: {probs[0]:.4f}")
707
+
708
+ This is a: stock photo.
709
+ Probability it's an amateur photo: 0.0007
710
+
711
+ # Pick a random image from the training set to display.
712
+ # (This should instead be one not from the training set, but this is just a quick test.)
713
+
714
+ import random
715
+ index = random.randint(0,total_num_images-1)
716
+ print(f"index: {index}")
717
+ random_image = get_image_files(path)[index]
718
+ photo_prediction,_,probs = learn.predict(tensor(PILImage.create(random_image)))
719
+ print(f"Prediction: {photo_prediction} photo")
720
+ print(f"Probability it's an amateur photo: {probs[0]:.4f}")
721
+ print(f"Probability it's a stock photo: {1.0-probs[0]:.4f}")
722
+ print(random_image)
723
+
724
+ Image.open(random_image).to_thumb(256,256)
725
+
726
+ index: 441
727
+
728
+ Prediction: stock photo
729
+ Probability it's an amateur photo: 0.0003
730
+ Probability it's a stock photo: 0.9997
731
+ stock_or_amateur/stock/24115c7c-4e28-4709-8472-63d8f6ef9a4e.jpg
732
+
733
+ Step 4: Analyze model
734
+
735
+ Now adding analysis and cleaning from lesson 2: https://github.com/fastai/fastbook/blob/master/02_production.ipynb
736
+
737
+ interp = ClassificationInterpretation.from_learner(learn)
738
+ interp.plot_confusion_matrix()
739
+
740
+ interp.plot_top_losses(6, nrows=1)
741
+
742
+ #hide
743
+ ! [ -e /content ] && pip install -Uqq fastbook
744
+ import fastbook
745
+ fastbook.setup_book()
746
+
747
+ #hide
748
+ from fastbook import *
749
+ from fastai.vision.widgets import *
750
+
751
+ #hide_output
752
+ cleaner = ImageClassifierCleaner(learn)
753
+ cleaner
754
+
755
+ Step 5: Export the trained model
756
+
757
+ learn.export('model.pkl')
758
+