Browse Source

Merge pull request #5 from prise-3d/dev/experiment

random choice of scenes and limited number of scenes for each experiment
Jérôme Buisine 6 months ago
parent
commit
c0d4fef5fe

+ 12 - 6
expe/config.py

@@ -30,12 +30,15 @@ expes_configuration            = {
 
     # First experiments configuration
     'quest_one_image':{
+        'scenes':['contemporary', 'bathroom'],
         'text':{
             'question': "Do you see one image or a composition of more than one?",
-            'indication': "press left if you see one image, right if not",
+            'indication': "press RIGHT if you see 2 images, LEFT if not",
             'end_text': "Experience is finished. Thanks for your participation",
             'examples': {
-                'sentence': "This images is cropped {0} with {1}%",
+                'sentence': ["First example of 2 images:\n This image is cropped {0}.\n {1}% on the left originating from a low-quality image and on the right originating from high quality. \n So, press RIGHT.", 
+                             "Second example of 1 image: \n This image is cropped {0}. \n {1}% on the left originating from a high-quality image and on the right originating from high quality, too.\n So, press LEFT", 
+                             "Third example of 2 images: \n This image is cropped {0}. \n {1}% on the upper part originating from a low-quality image and on the bottom originating from high quality. \n So, press RIGHT."],
                 'crop_params': [
                     [0.3, 0, 0],
                     [0.3, 0, 0],
@@ -49,11 +52,14 @@ expes_configuration            = {
             }
         },
         'params':{
-            'iterations': 10
-        },
-        'slopes':{
-
+            'iterations': 100,
+            'entropy': 5,
+            'slopes':{
+                'contemporary' : [0.0001, 0.001, 0.00003], #start, stop, step
+                'bathroom' : [0.0005, 0.01, 0.0003], #start, stop, step
+            },
         },
+        
         # if others custom session param are directly set for experiments
         'session_params': [
             'expe_data',

+ 12 - 2
expe/expes/run.py

@@ -63,9 +63,13 @@ def run_quest_one_image(request, model_filepath, output_file):
     # TODO : add specific thresholds information for scene
     #thresholds = np.arange(50, 10000, 50)
     stim_space = np.asarray(qualities)
+    
+    slope_range = cfg.expes_configuration[expe_name]['params']['slopes'][scene_name]
+    slopes = np.arange(slope_range[0], slope_range[1], slope_range[2]) 
     #slopes = np.arange(0.0001, 0.001, 0.00003) # contemporary
-    slopes = np.arange(0.0005, 0.01, 0.0003) # bathroom
-
+    #slopes = np.arange(0.0005, 0.01, 0.0003) # bathroom
+    #slopes = np.arange(1.995,19.95,0.5985)
+    
     # TODO : update norm slopes
     # stim_space = np.asarray(qualities)
     # slopes = np.arange(0.0001, 0.001, 0.00003)
@@ -113,6 +117,10 @@ def run_quest_one_image(request, model_filepath, output_file):
 
         output_file.write(line)
         output_file.flush()
+        
+        if entropy < cfg.expes_configuration[expe_name]['params']['entropy']:
+            request.session['expe_finished'] = True
+            return None
 
     # 5. Contruct new image and save it
     # construct image 
@@ -139,6 +147,8 @@ def run_quest_one_image(request, model_filepath, output_file):
     else:
         request.session['expe_finished'] = True
         return None
+    
+    
 
     # save image using user information
     # create output folder for tmp files if necessary

+ 2 - 2
expe/templates/expe/expe_indications.html

@@ -33,9 +33,9 @@
 
         <p id="expeIndication"><strong>Press enter to begin experiments</strong></p>
     {% else %}
+        <input type="hidden" name="scene_name" value="{{scene_name}}"/>
         <br/>
-        <h5>{{example_sentence}}</h5>
-        <br/>
+        <h5>{{example_sentence|linebreaks}}</h5>
         <img src="{{example}}" />
     {% endif %}
 

+ 10 - 9
expe/templates/expe/expe_list.html

@@ -16,15 +16,6 @@
 
                 <input type="hidden" name="example" value="0"/>
 
-                <div class="form-group">
-                    <label for="scene">Select scene:</label>
-                    <select class="form-control" name="scene">
-                        {% for scene in scenes %}
-                            <option value="{{scene}}">{{scene}}</option>
-                        {% endfor %}
-                    </select>
-                </div>
-
                 <div class="form-group">
                     <label for="expe" style="position:static">Select experiments:</label>
                     <select class="form-control " name="expe">
@@ -33,6 +24,16 @@
                         {% endfor %}
                     </select>
                 </div>
+                
+                <!-- <div class="form-group">
+                    <label for="scene">Select scene:</label>
+                    <select class="form-control" name="scene">
+                        {% for scene in scenes. %}
+                            <option value="{{scene}}">{{scene}}</option>
+                        {% endfor %}
+                    </select>
+                </div> -->
+
 
                 <button type="submit" class="btn btn-primary">Submit</button>
             </form>

+ 18 - 4
expe/views.py

@@ -68,17 +68,31 @@ def expe_list(request):
     # expe data
     data['scenes'] = scenes
     data['expes']  = expes
-
+    
+    #data['scenes'] = {}
+    #for expe in expes:
+    #    if 'scene' in cfg.expes_configuration[expe]:
+    #        data['scenes'][expe] = cfg.expes_configuration[expe]['scenes']
+    #    else:
+    #        data['scenes'][expe] = scenes
+            
     return render(request, 'expe/expe_list.html', data)
 
 
 def indications(request):
 
-    random.seed(10)
+    #random.seed(10)
 
     # get param 
     expe_name = request.GET.get('expe')
-    scene_name = request.GET.get('scene')
+    
+    scene_name = None
+    if 'scene' in request.GET:
+        scene_name = request.GET.get('scene')
+    
+    if scene_name is None or scene_name == 'null':
+        scene_name = random.choice(cfg.expes_configuration[expe_name]['scenes'])
+        
     example_number = request.GET.get('example')
 
     print(example_number)
@@ -116,7 +130,7 @@ def indications(request):
                                                                     orien=crop_params[1], 
                                                                     swap_img=crop_params[2])
 
-        example_sentence = cfg.expes_configuration[expe_name]['text']['examples']['sentence']
+        example_sentence = cfg.expes_configuration[expe_name]['text']['examples']['sentence'][int(example_number)]
 
         if orientation == 0:
             example_sentence = example_sentence.format('vertically', str(percentage*100))

+ 7 - 3
static/js/indications.js

@@ -6,14 +6,18 @@ const KEYCODE_RIGHT_ARROW = 39
 
 urlParams = new URLSearchParams(window.location.search)
 
-const scene    = urlParams.get('scene')
+var scene      = urlParams.get('scene')
 const expe     = urlParams.get('expe')
 var example    = urlParams.get('example')
 
-if (example === null || example === ''){
+if (example == null || example == ''){
      example = 0
 }
 
+if (scene === null || scene === ''){
+     scene = document.getElementsByName('scene_name')[0].value
+}
+
 const checkKey = e => {
      if (e.keyCode === KEYCODE_Q) {
           // `q` to quit expe
@@ -28,11 +32,11 @@ const checkKey = e => {
           window.location = expeUrl + params
      }
      else if (e.keyCode === KEYCODE_LEFT_ARROW || e.keyCode === KEYCODE_RIGHT_ARROW) {
-          
           // increment number of example
           example = parseInt(example) + 1
 
           console.log("I'm here")
+          
           // construct url with params for experiments
           const params = `?scene=${scene}&expe=${expe}&example=${example}`
           window.location = indicationsUrl + params