TheLastBen commited on
Commit
db42120
1 Parent(s): 3d51e60

Update Scripts/mainpaperspacev1.py

Browse files
Files changed (1) hide show
  1. Scripts/mainpaperspacev1.py +14 -8
Scripts/mainpaperspacev1.py CHANGED
@@ -305,8 +305,7 @@ def uplder(Remove_existing_instance_images, Crop_images, Crop_size, IMAGES_FOLDE
305
 
306
  if os.path.exists(INSTANCE_DIR+"/.ipynb_checkpoints"):
307
  call('rm -r '+INSTANCE_DIR+'/.ipynb_checkpoints', shell=True)
308
- if os.path.exists(CONCEPT_DIR+"/.ipynb_checkpoints"):
309
- call('rm -r '+CONCEPT_DIR+'/.ipynb_checkpoints', shell=True)
310
 
311
  uploader = widgets.FileUpload(description="Choose images",accept='image/*', multiple=True)
312
  Upload = widgets.Button(
@@ -338,6 +337,7 @@ def uplder(Remove_existing_instance_images, Crop_images, Crop_size, IMAGES_FOLDE
338
 
339
  def upld(Remove_existing_instance_images, Crop_images, Crop_size, IMAGES_FOLDER_OPTIONAL, INSTANCE_DIR, CAPTIONS_DIR, uploader, ren):
340
 
 
341
  if Remove_existing_instance_images:
342
  if os.path.exists(str(INSTANCE_DIR)):
343
  call("rm -r " +INSTANCE_DIR, shell=True)
@@ -352,6 +352,10 @@ def upld(Remove_existing_instance_images, Crop_images, Crop_size, IMAGES_FOLDER_
352
 
353
 
354
  if IMAGES_FOLDER_OPTIONAL !="":
 
 
 
 
355
  if any(file.endswith('.{}'.format('txt')) for file in os.listdir(IMAGES_FOLDER_OPTIONAL)):
356
  call('mv '+IMAGES_FOLDER_OPTIONAL+'/*.txt '+CAPTIONS_DIR, shell=True)
357
  if Crop_images:
@@ -367,7 +371,8 @@ def upld(Remove_existing_instance_images, Crop_images, Crop_size, IMAGES_FOLDER_
367
  image = file
368
  if file.size !=(Crop_size, Crop_size):
369
  image=crop_image(file, Crop_size)
370
- if (extension.upper() == "JPG" or "jpg"):
 
371
  image[0].save(new_path_with_file, format="JPEG", quality = 100)
372
  else:
373
  image[0].save(new_path_with_file, format=extension.upper())
@@ -392,7 +397,8 @@ def upld(Remove_existing_instance_images, Crop_images, Crop_size, IMAGES_FOLDER_
392
  extension = filename.split(".")[-1]
393
  identifier=filename.split(".")[0]
394
 
395
- if (extension.upper() == "JPG" or "jpg"):
 
396
  img.save(INSTANCE_DIR+"/"+filename, format="JPEG", quality = 100)
397
  else:
398
  img.save(INSTANCE_DIR+"/"+filename, format=extension.upper())
@@ -403,7 +409,7 @@ def upld(Remove_existing_instance_images, Crop_images, Crop_size, IMAGES_FOLDER_
403
  image = img
404
  if file.size !=(Crop_size, Crop_size):
405
  image=crop_image(file, Crop_size)
406
- if (extension.upper() == "JPG" or "jpg"):
407
  image[0].save(new_path_with_file, format="JPEG", quality = 100)
408
  else:
409
  image[0].save(new_path_with_file, format=extension.upper())
@@ -415,11 +421,11 @@ def upld(Remove_existing_instance_images, Crop_images, Crop_size, IMAGES_FOLDER_
415
  extension = filename.split(".")[-1]
416
  identifier=filename.split(".")[0]
417
 
418
- if (extension.upper() == "JPG" or "jpg"):
 
419
  img.save(INSTANCE_DIR+"/"+filename, format="JPEG", quality = 100)
420
  else:
421
  img.save(INSTANCE_DIR+"/"+filename, format=extension.upper())
422
-
423
 
424
  if ren:
425
  i=0
@@ -437,7 +443,6 @@ def upld(Remove_existing_instance_images, Crop_images, Crop_size, IMAGES_FOLDER_
437
  os.chdir('/notebooks')
438
 
439
 
440
-
441
  def caption(CAPTIONS_DIR, INSTANCE_DIR):
442
 
443
  paths=""
@@ -462,6 +467,7 @@ def caption(CAPTIONS_DIR, INSTANCE_DIR):
462
  text = f.read()
463
 
464
  img=Image.open(os.path.join(INSTANCE_DIR,path))
 
465
  img=img.resize((420, 420))
466
  image_bytes = BytesIO()
467
  img.save(image_bytes, format=ext, qualiy=10)
 
305
 
306
  if os.path.exists(INSTANCE_DIR+"/.ipynb_checkpoints"):
307
  call('rm -r '+INSTANCE_DIR+'/.ipynb_checkpoints', shell=True)
308
+
 
309
 
310
  uploader = widgets.FileUpload(description="Choose images",accept='image/*', multiple=True)
311
  Upload = widgets.Button(
 
337
 
338
  def upld(Remove_existing_instance_images, Crop_images, Crop_size, IMAGES_FOLDER_OPTIONAL, INSTANCE_DIR, CAPTIONS_DIR, uploader, ren):
339
 
340
+
341
  if Remove_existing_instance_images:
342
  if os.path.exists(str(INSTANCE_DIR)):
343
  call("rm -r " +INSTANCE_DIR, shell=True)
 
352
 
353
 
354
  if IMAGES_FOLDER_OPTIONAL !="":
355
+
356
+ if os.path.exists(IMAGES_FOLDER_OPTIONAL+"/.ipynb_checkpoints"):
357
+ call('rm -r '+IMAGES_FOLDER_OPTIONAL+'/.ipynb_checkpoints', shell=True)
358
+
359
  if any(file.endswith('.{}'.format('txt')) for file in os.listdir(IMAGES_FOLDER_OPTIONAL)):
360
  call('mv '+IMAGES_FOLDER_OPTIONAL+'/*.txt '+CAPTIONS_DIR, shell=True)
361
  if Crop_images:
 
371
  image = file
372
  if file.size !=(Crop_size, Crop_size):
373
  image=crop_image(file, Crop_size)
374
+ if extension.upper()=="JPG" or extension.upper()=="jpg":
375
+ image[0] = image[0].convert("RGB")
376
  image[0].save(new_path_with_file, format="JPEG", quality = 100)
377
  else:
378
  image[0].save(new_path_with_file, format=extension.upper())
 
397
  extension = filename.split(".")[-1]
398
  identifier=filename.split(".")[0]
399
 
400
+ if extension.upper()=="JPG" or extension.upper()=="jpg":
401
+ img=img.convert("RGB")
402
  img.save(INSTANCE_DIR+"/"+filename, format="JPEG", quality = 100)
403
  else:
404
  img.save(INSTANCE_DIR+"/"+filename, format=extension.upper())
 
409
  image = img
410
  if file.size !=(Crop_size, Crop_size):
411
  image=crop_image(file, Crop_size)
412
+ if extension.upper()=="JPG" or extension.upper()=="jpg":
413
  image[0].save(new_path_with_file, format="JPEG", quality = 100)
414
  else:
415
  image[0].save(new_path_with_file, format=extension.upper())
 
421
  extension = filename.split(".")[-1]
422
  identifier=filename.split(".")[0]
423
 
424
+ if extension.upper()=="JPG" or extension.upper()=="jpg":
425
+ img=img.convert("RGB")
426
  img.save(INSTANCE_DIR+"/"+filename, format="JPEG", quality = 100)
427
  else:
428
  img.save(INSTANCE_DIR+"/"+filename, format=extension.upper())
 
429
 
430
  if ren:
431
  i=0
 
443
  os.chdir('/notebooks')
444
 
445
 
 
446
  def caption(CAPTIONS_DIR, INSTANCE_DIR):
447
 
448
  paths=""
 
467
  text = f.read()
468
 
469
  img=Image.open(os.path.join(INSTANCE_DIR,path))
470
+ img=img.convert("RGB")
471
  img=img.resize((420, 420))
472
  image_bytes = BytesIO()
473
  img.save(image_bytes, format=ext, qualiy=10)